Add type annotations

Bug #1876591 reported by Brian Rutledge
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pkginfo
Fix Released
Wishlist
Unassigned

Bug Description

I've been working on adding type annotations to Twine (https://github.com/pypa/twine/issues/231), and pkginfo is one of our imports that's missing type hints/stubs. Is there any interest in adding those, either in the source or to https://github.com/python/typeshed?

See also: https://mypy.readthedocs.io/en/stable/existing_code.html

Revision history for this message
Tres Seaver (tseaver) wrote :

I'd be willing to review / merge such a branch and make a release. Due to time commitments, I'm not eager at this point to put in the work involved to drop Python2 support, so please keep that in mind if you are preparing such a branch.

Tres Seaver (tseaver)
Changed in pkginfo:
importance: Undecided → Wishlist
status: New → Triaged
Revision history for this message
Bartosz Sokorski (secrus) wrote :

hi, @tseaver are you open to a contribution involving dropping Python 2 and adding type annotations?

Revision history for this message
Tres Seaver (tseaver) wrote :

@secrus, I would be willing to review such contributions.

Ideally, the two parts (dropping Python2 support, adding type annotations) would be separated.

Per the following doc, because the test coverage is very good, automation of the annotations should be straightforward:

  https://mypy.readthedocs.io/en/stable/existing_code.html#automate-annotation-of-legacy-code

Note that the branch adding annotations should also add CI support to `tox.ini` (to prevent bitrot).

Revision history for this message
Tres Seaver (tseaver) wrote :

@secrus, I went to look at how involved the process of dropping 2.7 support would be, and ended up doing it myself in version 1.9.0.

Revision history for this message
Bartosz Sokorski (secrus) wrote :

@tseaver are you open to dropping Python 3.6 as well? It's long past being supported and having Python 3.7 as the lowest version, allows for usage of `from __future__ import annotations` for nicer typing syntax.

Revision history for this message
Tres Seaver (tseaver) wrote :

@secrus

> are you open to dropping Python 3.6 as well? It's long past being supported and having
> Python 3.7 as the lowest version, allows for usage of `from __future__ import annotations`
> for nicer typing syntax.

I'm mostly fine with dropping support for long-expired Python versions, but 3.6 is only a year into EOL, and was the default Python for several LTS Linux versions.

WRT typing, I'd honestly prefer to keep the typing annotations in separate stub files: I find the noise of them quite unpleasant when working in the code.

Revision history for this message
Tres Seaver (tseaver) wrote :

Stubs are added, and verified using 'mypy' in https://bazaar.launchpad.net/~tseaver/pkginfo/trunk/revision/213.

Changed in pkginfo:
status: Triaged → Fix Committed
Revision history for this message
Tres Seaver (tseaver) wrote :
Changed in pkginfo:
status: Fix Committed → Fix Released
Revision history for this message
Bartosz Sokorski (secrus) wrote :

@tseaver it seems that something is missing in setuptools config, because wheel does not contain neither `py.typed` file nor `.pyi` files.

Revision history for this message
Tres Seaver (tseaver) wrote :

@secrus

> it seems that something is missing in setuptools config,
> because wheel does not contain neither `py.typed` file nor
> `.pyi` files.

Ugh. 1.9.4 should fix that:

  https://pypi.org/project/pkginfo/1.9.4/

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.