Skip to content

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

Merged
merged 3 commits into from
Jul 19, 2017

Conversation

ddfisher
Copy link
Collaborator

@ddfisher ddfisher commented Jul 10, 2017

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.

@gvanrossum gvanrossum mentioned this pull request Jul 18, 2017
JukkaL pushed a commit that referenced this pull request Jul 18, 2017
@ddfisher
Copy link
Collaborator Author

@gvanrossum this should be ready to review now!

Copy link
Member

@gvanrossum gvanrossum left a 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

Copy link
Member

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.

Copy link
Collaborator Author

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]"
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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!

@gvanrossum gvanrossum merged commit 8709da5 into master Jul 19, 2017
@gvanrossum gvanrossum deleted the fix-none-args branch July 19, 2017 01:46
@gvanrossum
Copy link
Member

Should be cherry-picked into 0.521.

gvanrossum pushed a commit to gvanrossum/mypy that referenced this pull request Jul 24, 2017
gvanrossum pushed a commit to gvanrossum/mypy that referenced this pull request Jul 24, 2017
…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.
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