Skip to content

Type annotations aren't discoverable #50

Closed

Description

@DMRobertson

#49 added annotations. But mypy won't go looking for them unless we mark the module as having annotations:

$ pip show canonicaljson | \grep ^Version
Version: 1.6.1
$ grep canonicaljson mypy.ini
$ mypy
synapse/__init__.py:67: error: Skipping analyzing "canonicaljson": module is installed, but missing library stubs or py.typed marker  [import]
synapse/__init__.py:67: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

We need a py.typed marker file, but there's no way to do that for single-file modules. https://peps.python.org/pep-0561/#packaging-type-information writes:

This PEP does not support distributing typing information as part of module-only distributions or single-file modules within namespace packages.

The single-file module should be refactored into a package and indicate that the package supports typing [by including a py.typed marker file].

Activity

  1. DMRobertson commented on Sep 22, 2022

    @DMRobertson
    ContributorAuthor

    Fix here is to make this a proper package

    • rename canonicaljson.py -> __init__.py
    • make a new directory canonicaljson and move __init__.py into it
    • create blank py.typed file in the canonicaljson directory and ensure it's distributed once this is packaged up
    • figure out any other pacakging problems
    • make a release

    Edit: for bonus points, update Synapse to

    • use the new release of canonicaljson in the poetry lockfile
    • no longer ignore imports from canonicaljson
  2. self-assigned this
    on Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions