Skip to content

Force-enable strict optional only when checking for unsafe overlaps #5252

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

Conversation

Michael0x2a
Copy link
Collaborator

Resolves #5246

Previously, we force-enabled strict optional checks when performing all overload definition checks. This ended up causing mypy to miss some errors in definitions when --no-strict-optional mode is enabled.

This commit will now force-enable strict optional only when checking if overloads are unsafely overlapping: we use the existing mode when checking if one variant completely eclipses another or when checking the implementation.

@Michael0x2a
Copy link
Collaborator Author

As a note, these tests will currently fail. They should start passing once python/typeshed#2261 is merged and I do the typeshed sync dance.

Resolves python#5246

Previously, we force-enabled strict optional checks when performing all
overload definition checks. This ended up causing mypy to miss some
errors in definitions when `--no-strict-optional` mode is enabled.

This commit will now force-enable strict optional only when checking if
overloads are unsafely overlapping: we use the existing mode when
checking if one variant completely eclipses another or when checking the
implementation.
@Michael0x2a Michael0x2a force-pushed the tighten-strict-optional-mode-in-overload-defn-checks branch from 9c7687b to 5cbfa5c Compare June 20, 2018 17:13
@Michael0x2a Michael0x2a requested a review from ilevkivskyi June 20, 2018 17:39
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

LGTM!

The extra bogus errors still appear after we detect unsafety, but they are unrelated to overloads but to failed type variable inference with the first match. A potential option (in a separate PR, low priority) would be to somehow mark unsafe (or otherwise broken) overload definitions and return Any(TypeOfAny.from_error) at the call sites to limit bogus errors.

@ilevkivskyi ilevkivskyi merged commit bd9e93b into python:master Jun 21, 2018
@Michael0x2a Michael0x2a deleted the tighten-strict-optional-mode-in-overload-defn-checks branch July 9, 2018 04:18
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