SymPy is a Python library for symbolic mathematics with thousands of contributors. I contributed type annotations to its sympy.utilities.exceptions module as part of the broader effort to improve static type checking across the codebase (Issue #28806).
What Changed
The PR (#29376) added type annotations to three public APIs in sympy/utilities/exceptions.py:
SymPyDeprecationWarning— the main deprecation warning classsympy_deprecation_warning— the helper function for issuing deprecation warningsignore_warnings— a context manager for suppressing warnings in tests
The annotations use a TYPE_CHECKING guard to keep collections.abc out of the runtime import path, which avoids unnecessary overhead and aligns with the project's conventions.
No runtime behavior was changed. The goal was purely to improve mypy coverage and make the APIs more self-documenting.
Review Process
The initial draft imported collections.abc with a # noqa: TC003 comment to suppress the type-checking import warning. The maintainer (oscarbenjamin) reviewed and suggested moving it into a TYPE_CHECKING block instead. I updated the patch and it was merged shortly after.
It's a small contribution, but working inside a large, well-maintained open source project with strict style conventions is its own kind of exercise.
Verification
Tested locally before submission:
python -m mypy sympy
python -m pytest sympy/utilities/tests/test_exceptions.py -q
python -m pytest sympy/testing/tests/test_pytest.py -q
python -m pytest sympy/utilities/tests/test_pickling.py -q
ruff check sympy/utilities/exceptions.py