Skip to content
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

Allow stubs to depend on numpy #9499

Merged
merged 1 commit into from
Jan 12, 2023
Merged

Allow stubs to depend on numpy #9499

merged 1 commit into from
Jan 12, 2023

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jan 11, 2023

Currently, if a stubs package declares a dependency on numpy, the latest version of numpy will be installed in CI when testing that package. However, the CI will then fail, because mypy will detect that numpy is using PEP-570 syntax, and accordingly will emit errors when run with the --python-version=3.7 flag, since PEP 570 is new in Python 3.8.

The solution is to actually run mypy on 3.7 in CI, rather than simply running mypy with the --python-version=3.7 flag. If we run mypy on 3.7, pip's dependency resolver will understand that the latest version of numpy isn't compatible with the version of Python we're using, and will give us an older version of numpy that's compatible with Python 3.7.

A few tweaks to tests/mypy_test.py and tests/utils.py are required in order to make them compatible with Python 3.7. We also can't install the whole of requirements-tests.txt on Python 3.7, since flake8==6.0.0 is not compatible with Python 3.7.

Helps unblock #8974

@hauntsaninja
Copy link
Collaborator

Hmm, not sure we should do this. numpy types have evolved a lot in recent versions

@AlexWaygood
Copy link
Member Author

Hmm, not sure we should do this. numpy types have evolved a lot in recent versions

An alternative solution might be to add a requires_python field to the METADATA.toml files. We could use that to declare that e.g. types-tensorflow requires Python 3.8+, and also skip testing those stubs when running mypy with --python-version=3.7.

@hauntsaninja
Copy link
Collaborator

Actually, this is fine, since we'll test with new numpy on new Python. (assuming the (lack of) improvements in a numpy don't cause trouble for us)

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@AlexWaygood AlexWaygood merged commit 0b90344 into main Jan 12, 2023
@AlexWaygood AlexWaygood deleted the allow-numpy branch January 12, 2023 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants