-
-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup mypy in tox -e typing
and get it to pass
#892
Commits on Jan 5, 2022
-
Setup mypy in
tox -e typing
and get it to passThis is the smallest possible change to get mypy passing on the jsonschema codebase. The goal of this configuration is to enforce type annotations anywhere that they appear. That is, if a method is added to the codebase, def foo(x: int) -> str: return str(x) then usages of `foo` will by type checked. If no annotations are added, `mypy` will not type check functions. For the most part, this keeps the impact low. The one exceptional case is the use of `pyrsistent.pmap` as an argument to `attr.ib(converter=...)`. Unfortunately, it causes `mypy` to incorrectly deduce the type of the init parameter created by attrs. We need to "explain the type of init" to mypy by creating a callable with a concrete type to act as the converter. The callable in question simply wraps `pmap` with a cast and presents the desired type information to mypy.
Configuration menu - View commit details
-
Copy full SHA for 5a2f8ee - Browse repository at this point
Copy the full SHA 5a2f8eeView commit details -
Fix typing_extensions import handling for mypy
mypy can handle `if sys.version_info` checking better than `try ... except ImportError`. This is somewhat disappointing, but the rewrite of these import lines isn't that bad and aligns with the recommendations of the mypy docs.
Configuration menu - View commit details
-
Copy full SHA for a8c131b - Browse repository at this point
Copy the full SHA a8c131bView commit details -
Parenthesize dict-tuple to pacify pypy3.7 parser
In pypy3, the following line is invalid: x: Tuple[dict, dict] = {}, {} but this variant *is* valid: x: Tuple[dict, dict] = ({}, {}) Apply this correction where it occurs in test_validators.py
Configuration menu - View commit details
-
Copy full SHA for ec8dab1 - Browse repository at this point
Copy the full SHA ec8dab1View commit details -
Use future import for type annotations
Use of the `__future__` import of annotations allows several niceties, in particular: - parametrization of builtin types as generics - `|` syntax for unions (including `| None` for optionals) Update to use the future import wherever it improves or simplifies annotations. Avoid using new typing features outside of annotations (e.g. in assignment), which fails on older pythons. This is an unfortunate wart in the way that the future import works.
Configuration menu - View commit details
-
Copy full SHA for 2474242 - Browse repository at this point
Copy the full SHA 2474242View commit details -
Fix nitpick error on type annotation
Nitpick was failing on TYPE_CHECKER: ClassVar[TypeChecker] It's not clear what to do about this. `TypeChecker` was imported correctly from `jsonschema._types` and is noted in the doc as `jsonschema.TypeChecker`. We can't import the `jsonschema` name at runtime because that would be circular. To resolve, use `typing.TYPE_CHECKING` to conditionally import `jsonschema` at type-checking time. This avoids the circular import but allows us to write TYPE_CHECKER: ClassVar[jsonschema.TypeChecker] As a result, Sphinx correctly builds a cross-reference from the annotation, the annotation is still accurate, and runtime behavior is left untouched.
Configuration menu - View commit details
-
Copy full SHA for 631fba1 - Browse repository at this point
Copy the full SHA 631fba1View commit details -
Fix sphinx nitpick error arising from annotations
Type annotations can use variable names in order to support easily named constructs (e.g. `FooType = Union[int, str]; x: FooType`). However, such variable names are then seen by sphinx autodoc, which does not evaluate them. As a result, for such a name to avoid tripping nitpick warnings, these names need to be resolvable. The simplest resolution is to remove the use of any internal variables for this purpose (at least where they would be seen by sphinx), and use the longhand description of types in such cases.
Configuration menu - View commit details
-
Copy full SHA for 17384e7 - Browse repository at this point
Copy the full SHA 17384e7View commit details -
Cleanup internal type annotation variables
`_format.py` had a few internal variables to make type annotations shorter to write. However, these can cause issues with sphinx nitpick. Even though the variables removed in this commit aren't causing a build failure, removing them is a good precaution.
Configuration menu - View commit details
-
Copy full SHA for cdc2807 - Browse repository at this point
Copy the full SHA cdc2807View commit details -
Omit 'if TYPE_CHECKING' blocks from coverage
These blocks only exist to create code which evaluates under mypy but does not run at runtime. As a result, they are impossible to cover with `coverage` on a testsuite, and make sense to exclude from coverage reporting.
Configuration menu - View commit details
-
Copy full SHA for 811bab2 - Browse repository at this point
Copy the full SHA 811bab2View commit details
Commits on Jan 6, 2022
-
Configuration menu - View commit details
-
Copy full SHA for bc4f2d5 - Browse repository at this point
Copy the full SHA bc4f2d5View commit details