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

Enable strict optional for more test files (3) #15597

Merged
merged 3 commits into from
Jul 7, 2023

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Jul 5, 2023

Followup to #15586

@@ -1090,7 +1090,7 @@ optional2(10)
optional2('test')

def optional3(x: Optional[List[Any]]):
assert not x
assert x
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't quite understand this one!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tbh I didn't either. assert not x doesn't make much sense here. I only excludes the non-empty list. With strict optional, that results in an error for the next line where

    return x[0]  # E: Value of type "Optional[List[Any]]" is not indexable

To keep the intention, the assert should probably be assert not x and x is not None but I wasn't sure this would be better than just assert x.

@@ -1090,7 +1090,7 @@ optional2(10)
optional2('test')

def optional3(x: Optional[List[Any]]):
assert not x
assert x
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
assert x
assert not x and x is not None

This would work as well, although as mentioned earlier, I'm not convinced it's better. Feel free to accept or dismiss it.

@hauntsaninja hauntsaninja merged commit 6cd8c00 into python:master Jul 7, 2023
12 checks passed
@cdce8p cdce8p deleted the test-optional-3 branch July 7, 2023 18:45
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