Commit Graph
11 Commits
Author SHA1 Message Date
Stephen Rosen 2c534dc220 Improve annotation of jsonschema.validators.create (#8608) 2022-08-25 15:25:15 +02:00
Stephen Rosen 199132122b Add pre-commit config for flake8 (#8068)
This makes it easier to lint your own work with `pre-commit`, but doesn't change the CI config by adding this to the pre-commit.ci skip list.

There's no way to automatically reflect the additional dependencies from the requirements file, so the flake8 plugin list needs to be a verbatim copy.

resolves #7991
2022-06-14 02:30:09 +01:00
Stephen RosenandSebastian Rittau 17e7cc7d3c Fix exception types for jsonschema._format (#7990)
The annotated type for the `raises` argument on format checkers was

    Exception | tuple[Exception, ...]

when it should read

    type[Exception] | tuple[type[Exception], ...]

Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
2022-05-30 17:14:33 +01:00
Stephen Rosen b2aaed1e68 Fix jsonschema exception str|int containers (#7981)
schema_path, relative_schema_path, and absolute_schema_path are all
(related) attributes of `jsonschema` errors which contain `str | int`
but were accidentally annotated as containing `str`. Fix them for
accuracy.
2022-05-29 22:22:34 +01:00
Stephen Rosen f52da1e8b0 Flesh out more of jsonschema stubs (#7950)
Apply more detailed annotations to the format module and most of the
exceptions module.
2022-05-27 17:33:32 +01:00
Stephen Rosen 134f047402 jsonschema: mark schemas as Mapping[str, Any] (#7489) 2022-03-14 17:11:33 +01:00
Stephen Rosen a3027d3b96 jsonschema: RefResolver.referrer is a dict[str, Any] (#7487) 2022-03-14 16:27:08 +01:00
Stephen Rosen 38d32a916c Use enum trick for dataclasses.MISSING (#7127)
The goal of this change is to fix the behavior of
`dataclasses.Field`. Several attributes of a `Field` may have a value
of `MISSING` (a sentinel value). As a result, attributes of Field may
be checked against `MISSING` as in

     [f for f in fields(obj) if f.default is MISSING]

`default`, `default_factory`, and `kw_only` are the attributes
which may have a value of `MISSING`.

This workaround of defining `_MISSING_TYPE` as an enum, and `MISSING`
as its only member, allows `... | Literal[_MISSING_TYPE.MISSING]` to
be used in type annotations for these attributes. This is very
slightly inaccurate -- primarily in that `_MISSING_TYPE` isn't really
an enum -- but this allows for use in `Literal`.
After PEP 661 (Sentinel Values), there may be a more accurate way of
writing this, but for now this works.

This adjustment is only applied to the attributes of Field, not the
arguments to functions and methods.
2022-02-04 21:21:12 -08:00
Stephen Rosen 806a5bcece Add jsonschema.protocols to library stubs (#6614)
`jsonschema.protocols.Validator` was introduced in `jsonschema` v4.3.0
It's also available under the name `jsonschema.Validator`.
2021-12-17 13:30:58 +01:00
Stephen Rosen df0a724c0f Always import Protocol from typing in stubs (#6617) 2021-12-17 13:12:22 +01:00
Stephen Rosen 6a9c7aff99 Add missing exceptions to requests __init__.pyi (#5840) 2021-08-02 07:29:28 -07:00