FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make strict Optional type system changes standard by ddfisher · Pull Request #3024 · python/mypy · GitHub

Repository navigation

Make strict Optional type system changes standard - #3024

Merged
JukkaL merged 7 commits into
masterfrom
per-file-strict-optional
Mar 19, 2017
Merged

JukkaL merged 7 commits into
masterfrom
per-file-strict-optional

Conversation

Copy link
Copy Markdown
Collaborator

After this lands, per-file strict Optional should be straightforward. This should fix a lot of bugs around None. Introduces a small bug with partial types (where mypy is overly permissive) which will be fixed in a follow up PR.

ddfisher force-pushed the per-file-strict-optional branch from 06ae294 to c0350ca Compare March 19, 2017 00:44
ddfisher force-pushed the per-file-strict-optional branch from c0350ca to 9f73487 Compare March 19, 2017 00:49
ddfisher force-pushed the per-file-strict-optional branch from 9f73487 to 5c44790 Compare March 19, 2017 01:32
def g(self) -> None: pass
[out]
main:6: error: Return type of "f" incompatible with supertype "A"
main:7: error: Return type of "g" incompatible with supertype "A"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why is this no longer an error?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

None is a subtype of A, so this is valid.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Well, only without --strict-optional, or if the base class has -> Optional[A].

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sure, but --strict-optional is still not enabled by default.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah, I was confused by the PR title (and didn't read the whole thing).

JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nice! This simplifies things a lot and improves consistency.

Comment thread mypy/checker.py
# Lambdas are allowed to have None returns.
# Functions returning a value of type None are allowed to have a None return.
if isinstance(self.scope.top_function(), FuncExpr) or isinstance(typ, NoneTyp):
if is_lambda or isinstance(typ, NoneTyp):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is unclear.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Added some comments

Comment thread test-data/unit/check-inference.test Outdated
def ff() -> None:
x = f() # E: Need type annotation for variable
x = f()
reveal_type(x)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There's no output from reveal_type. The desired behavior would probably be to require an annotation for x.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Filed issue for this instead: #3032.

def g(a: T) -> None: pass
[out]

[case testUnsolvableInferenceResult]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Consider enabling this test case and renaming it if the output doesn't correspond to the original intent of the test case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is a test involving void and is no longer relevant. It no longer tests anything interesting that is untested elsewhere.

a = x

for y in []: # E: Need type annotation for variable
for y in []:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What's the type of y here? I think that the original message was fine. At least add a reveal_type.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

y is inferred as None. Added a reveal_type.

a = y

for e, f in [[]]: # E: Need type annotation for variable
for e, f in [[]]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Similar to above; at least add reveal_types.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done.


[case testPartiallyInitializedToNoneAndThenToIncompleteType]
[case testPartiallyInitializedToNoneAndThenToIncompleteType-skip]
# TODO(ddfisher): fix partial type bug and re-enable

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Add an issue for this so that we won't lose track of it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Comment thread test-data/unit/pythoneval-asyncio.test Outdated
def test() -> 'Generator[Any, None, None]':
yield from greet()
x = yield from greet() # Error
x = yield from greet()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

For consistency, we should retain the original error message (... does not return a value).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL