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
Typing [Fixed #1489!] #1536
Typing [Fixed #1489!] #1536
Conversation
Wow this is really great! |
Thanks! Happy to help :) I would like to point out some specific difficulties I faced, so you can better understand my decisions made:
import platform
major, minor, patchlevel = (int(version) for version in platform.python_version_tuple())
if major > 3 or major == 3 and minor >= 10: # Python 3.10 and above
from collections import OrderedDict
elif major == 3 and (minor < 7 or minor == 7 and patchlevel < 2): # Python 3.7.1 and below
from typing import MutableMapping as OrderedDict
else:
from typing import OrderedDict
|
Fix last type errors
- Removed redundant TypeVar from Generator - Ordered typing.py in alphabetical order
|
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.
Looks good :-)
Two open questions
- can we add the mypy step to the
lint
step of the CI? - should we squash the commits before merging ?
I would suggest to keep this separate, since the
Yes, I agree we should do that. I think @fcurella should have an option 'squash and merge' to do that directly when applying it. Perhaps refer to docs/coding_style.rst in the description of that squashed commit? |
@MarcelRobeer I can do the squashing, no worries! :) |
I agree in having it as a separate step. Ideally, I'd like to run it in parallel with the |
Implemented this. It now passes all tests. Note that I had to add the |
Thank you so much @MarcelRobeer , amazing work! ✨ @nicarl could you give this one last review? |
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.
Just some last minor comments, once they are fixed it is good from my side 👍
This is awesome! Thank you so much! |
try: | ||
from typing import Literal # type: ignore | ||
except ImportError: | ||
from typing_extensions import Literal # type: ignore |
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.
@nicarl @MarcelRobeer
Should the package typing-extensions
be a dependency in setup.py?
typing-extensions>=3.6.4; python_version < "3.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.
Not sure if typing-extensions is installed by default in earlier Python versions, or that it is installed on-the-go because of the --install-types
flag for mypy
in tox.ini
? @nicarl do you know this by any chance?
When running tests this doesn't seem to form an issue; not sure if it pops up as an issue when running the code yourself?
[Edit 1]: looking at the typing (3.6)
test it seems like it is installed together with other dependencies when setting up the python environment for tox
:
Collecting typing-extensions>=3.6.4
Downloading typing_extensions-3.10.0.2-py3-none-any.whl (26 kB)
[Edit 2]: Looks like typing-extensions
is a dependency of mypy
, which installs it by default: https://github.com/python/mypy/blob/f5fc579cf07f2078c9312044f6bcb132f891d746/setup.py
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.
Apparently, Literal
is included in typing
only in Python 3.8 and above.
And typing_extensions
is not included at least in Python 3.6, 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.
@obieler thanks for digging that deep!
I just tried with Python 3.6.0 and 3.7.0 and typing_extensions
is not contained.
Adding mypy
to setup.py
should solve the problem as it contains typing-extensions
as dependency. At the same time one could pin mypy
version to 0.910 as recommend in https://sethmlarson.dev/blog/2021-10-18/tests-arent-enough-case-study-after-adding-types-to-urllib3
Edit: opening a PR in a minute
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 saw the fix in 9.5.1, thank you!
What does this change?
Added type annotation hints to all functions/classes in
faker
!What was wrong
faker
did not include type annotations (issue #1489).How this fixes it
monkeytype
(https://monkeytype.readthedocs.io/en/latest/) for all files in which it did not throw errors.None
). Did a lot of code analysis myself, but would also like to credit @nicarl for his earlier work on type annotations (e.g. indocumentory.py
andgenerator.py
).mypy
compliant (mypy -m faker
). Also addedmypy -m faker
test totox.ini
!flake8
compliant (flake8 faker tests
)isort
compliant (python3 -m isort --check-only --diff .
)