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

Use --no-implicit-optional for type checking #11374

Merged
merged 4 commits into from
Aug 13, 2022

Conversation

hauntsaninja
Copy link
Contributor

This makes type checking PEP 484 compliant (as of 2018).
mypy will change its defaults soon.

See:
python/mypy#9091
python/mypy#13401

This makes type checking PEP 484 compliant (as of 2018).
mypy will change its defaults soon.

See:
python/mypy#9091
python/mypy#13401
@pradyunsg pradyunsg merged commit 7efc814 into pypa:main Aug 13, 2022
@pradyunsg
Copy link
Member

Thanks for this @hauntsaninja! ^>^

We still have a bunch of strict-optional=False set at the file-level on a bunch of files, in case you're interested in making more changes in a similar direction. :)

@hauntsaninja hauntsaninja deleted the implicit-optional branch August 13, 2022 16:14
hauntsaninja added a commit to hauntsaninja/pip that referenced this pull request Aug 14, 2022
Suggested by pradyunsg in pypa#11374

Since half of the API of this class depends on self.req not being None,
it seems like we should just prevent users from passing None here.
However, I wasn't able to make that change.

Rather than sprinkle asserts everywhere, I added "checked" properties.
I find this less ad hoc and easier to adapt if e.g. we're able to make
self.req never None in the future.

There are now some code paths where we have asserts that we didn't
before. I relied on other type hints in pip's code base to be accurate.
If that is not the case and we actually relied on some function being
able to accept None when not typed as such, we may hit these asserts.
But hopefully tests would catch such a thing.
hauntsaninja added a commit to hauntsaninja/pip that referenced this pull request Aug 14, 2022
Suggested by pradyunsg in pypa#11374

Since half of the API of this class depends on self.req not being None,
it seems like we should just prevent users from passing None here.
However, I wasn't able to make that change.

Rather than sprinkle asserts everywhere, I added "checked" properties.
I find this less ad hoc and easier to adapt if e.g. we're able to make
self.req never None in the future.

There are now some code paths where we have asserts that we didn't
before. I relied on other type hints in pip's code base to be accurate.
If that is not the case and we actually relied on some function being
able to accept None when not typed as such, we may hit these asserts.
But hopefully tests would catch such a thing.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants