-
-
Notifications
You must be signed in to change notification settings - Fork 30
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 annotations #62
Type annotations #62
Conversation
crusaderky
commented
Mar 5, 2022
•
edited
Loading
edited
- Annotate everything
- Enforce mypy validation in CI
- Let mypy running on other packages read type annotations from zict
- Move contents of setup.py to setup.cfg
- Blocked by zict type annotations distributed#5905
- Follow-up: Dictionary views #61
- Follow-up: Cannot assign to field of Callable type python/mypy#708
name = zict | ||
version = 2.2.0.dev1 | ||
maintainer=Matthew Rocklin | ||
maintainer_email=mrocklin@coiled.io |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change this to a mailing list of the coiled OSS team?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that'd be a good idea, but shouldn't hold up the PR.
name = zict | ||
version = 2.2.0.dev1 | ||
maintainer=Matthew Rocklin | ||
maintainer_email=mrocklin@coiled.io |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that'd be a good idea, but shouldn't hold up the PR.
Operating System :: OS Independent | ||
Programming Language :: Python | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any harm in dropping 3.7 here? that would let you implement some of the TODOs in the comments that don't work on 3.7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just two small bits; I didn't think it was worth the effort of gathering consensus.
from collections import defaultdict | ||
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in common.py and zip.py, MutableMapping
is imported from the typing
module for compatibility with python <3.9.
But I think MutableMapping
has been in python for a while now:
https://docs.python.org/3.7/library/collections.abc.html#collections.abc.MutableMapping
Do we rely on a specific implementation that's only available in > Python3.8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python 3.9+, collections.abc.MutableMapping introduces support for square brackets like typing.MutableMapping does.
In other places we're importing from collections.abc; that's because those are modules where MutableMapping[...] is used exclusively in delayed type annotations, which are not parsed by the python interpreter.
In this module however MutableMapping[...] is used as a base class, which means at runtime.
import zipfile | ||
from collections.abc import Iterator | ||
from typing import MutableMapping # TODO move to collections.abc (needs Python >=3.9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load: Callable[[WT], VT], | ||
d: MutableMapping[KT, WT], | ||
): | ||
# FIXME https://github.com/python/mypy/issues/708 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that issue is quite a ride. This hack is particularly fun, though probably a bad idea.