Skip to content
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

Type annotate format checker methods #958

Merged
merged 3 commits into from Jun 2, 2022

Commits on May 30, 2022

  1. Type annotate format checker methods

    The goal of this work is to apply annotations in `jsonschema._format`
    which match the new additions to the type stubs recently added to
    typeshed.
    
    In short, it defines a `_FormatCheckCallable` as a callable --
    typically function -- which takes any object and returns a bool.
    All of the `is_*` functions are `_FormatCheckCallable`s, and the
    decorators are carefully annotated as being type-preserving using a
    typevar.
    
    Because the returned objects from these functions are not always
    bools, this changeset now calls `bool()` on those which are not (e.g.
    `ipaddress.IPv4Address`). This is really just an explicit form of the
    check which is going to happen in `conforms` and `check` anyway, so
    there's no significant new cost. The advantage of this is that we have
    documented (via the annotations) what a format check function is
    supposed to do: it returns a bool. We could equally well return `Any`
    from these functions, relying on `__bool__`, but this could confuse
    new contributors and users.
    
    One unfortunate side effect of these changes is that
    `FormatChecker.cls_checks` needs to be expanded into a full duplicate
    of `FormatChecker.checks`. `mypy` isn't able to properly understand
    what `cls_checks = classmethod(checks)` does -- this is part of a
    class of semi-sophisticated callable and method manipulations that are
    known to be problematic for `mypy`. In order to get the annotations
    correct, the simplest solutions are either to annotate it explicitly
    (cast or type comment) or to expand it as this changeset has done.
    sirosen committed May 30, 2022
    Copy the full SHA
    8d6e113 View commit details
    Browse the repository at this point in the history

Commits on Jun 2, 2022

  1. Copy the full SHA
    af47da8 View commit details
    Browse the repository at this point in the history
  2. Merge branch 'main' into bool-format-checks

    * main:
      Slightly speed up pip installs by skipping the version check in CI.
      Remove the now-unused MANIFEST.in.
      v4.6.0 -> CHANGELOG
      Ignore the badge URLs, they seem super unreliable from CI.
      Ignore a deprecation warning coming from pkg_resources on 3.11
      Add basic CONTRIBUTING guidelines.
      Make project.urls be valid URLs.
      Combine the CI and packaging workflows.
      Let RTD be authoritative about what the default doc version is.
      Re-enable Python 3.11 testing in CI.
      Modernize the packaging setup via PEP 621 and Hatch.
      Update various GHA versions.
      Update docs requirements.
      Revert "Merge pull request python-jsonschema#954 from ssbarnea/fix/py.typed"
    Julian committed Jun 2, 2022
    Copy the full SHA
    ded065d View commit details
    Browse the repository at this point in the history