-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix per-file strict Optional interaction with default-None args #3686
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
Helpful for the right fix in #3686.
@gvanrossum this should be ready to review now! |
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.
LG, a few style nits.
strict_optional = False | ||
[[mypy-optional] | ||
strict_optional = True | ||
|
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.
You don't really need three blank lines here, just one. :-) Also IMO you can drop the single blank lines above.
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.
Fixed the three blank lines. The lines between the files make them much more readable to me (though it looks like one got dropped, so I added it back).
@@ -363,7 +363,7 @@ y = x # E: Incompatible types in assignment (expression has type Callable[..., | |||
|
|||
a, b = None, None # type: (A, B) | |||
a = f() # E: Incompatible types in assignment (expression has type "B", variable has type "A") | |||
b = f(b) # E: Argument 1 to "f" has incompatible type "B"; expected "A" | |||
b = f(b) # E: Argument 1 to "f" has incompatible type "B"; expected "Optional[A]" |
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 wonder if it makes more sense to change the definition of f() to use A() as the default value? Ditto for the next test below.
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.
It looks to me like those functions are partially testing forward references? (Not sure why they'd be structured like that otherwise.) I can't use A() when it's a forward reference.
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.
Hm, I think that's just how Jukka used to write tests, with the classes/functions at the end. A lot of them have that. Anyway I'll merge now!
Should be cherry-picked into 0.521. |
Helpful for the right fix in python#3686.
…on#3686) With per-file strict Optional, default-None args should always be interpreted as Optional (except with --no-implicit-optional), instead of only in strict Optional files.
With per-file strict Optional, default-None args should always be interpreted as Optional (except with
--no-implicit-optional
), instead of only in strict Optional files.