-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Narrower typing on Factory called with takes_self #780
Conversation
Looks like it's blowing up because of python/typed_ast#156 which was only fixed four days ago in python/typed_ast#155. There's been no release yet, so for the moment MyPy is uninstallable on CPython 3.10.0a6 and later. I think using 3.10.0a5 or lower might fix the issue? |
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.
Thanks for doing this! Lovely to see more people get involved in the type annotations.
I think the problem won't be which python you're running but which python you're type-checking for.
For example:
[mypy]
python_version=3.7
or --python-version 3.7
What appears to happen in that case is that Literal
doesn't exist and the type of takes_self
gets an Any. This sees happens silently by the way (at least when I ran it I got no error messages). I left comments on how to fix this.
I wonder if we could convince mypy to allow using Literal
in stub files even if they aren't present in the current python. Literal is just so useful.
Pre-commit’s isort is failing for |
Thanks! |
This changes the annotations for
attr.Factory
so that the acceptable type of the callable changes based ontakes_self
.Theoretically, MyPy will let you do this:
The change in annotations will prevent that from happening.
As written I think these annotations would require the type checker to be running on Python 3.8 because of the use of
Literal
. There are a couple ways around this, if necessary.Pull Request Check List
.pyi
).tests/typing_example.py
.docs/api.rst
by hand.@attr.s()
have to be added by hand too.versionadded
,versionchanged
, ordeprecated
directives. Find the appropriate next version in our__init__.py
file..rst
files is written using semantic newlines.changelog.d
.