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

Optional[T] in {None,...} does not drop the Optional #8787

Closed
Carreau opened this issue May 7, 2020 · 3 comments
Closed

Optional[T] in {None,...} does not drop the Optional #8787

Carreau opened this issue May 7, 2020 · 3 comments
Labels
feature topic-type-narrowing Conditional type narrowing / binder

Comments

@Carreau
Copy link
Contributor

Carreau commented May 7, 2020

On latest mypy; of course the code can use if not var: which would have the same effect.

$ cat foo.py
import os

var = os.environ.get('ENV')
if var in {None, ''}:
    var = 'default'
else:
    var =  var.lower()
$ mypy foo.py
foo.py:7: error: Item "None" of "Optional[str]" has no attribute "lower"
Found 1 error in 1 file (checked 1 source file)
$ mypy --version
mypy 0.770+dev.2d06ba71aa087e8d8a6eb4a37bb9a6254f7dbb70

Thanks

@EkanshMangal
Copy link

Hello Sir
Can i fix this issue?

@Carreau
Copy link
Contributor Author

Carreau commented May 7, 2020

Hi @EkanshMangal,

I see there is a Contributing file on this repository I would suggest starting there for instructions.

@AlexWaygood AlexWaygood added feature topic-type-narrowing Conditional type narrowing / binder labels Apr 4, 2022
@AlexWaygood
Copy link
Member

Closing as a duplicate of #10977, which is a newer issue but has a lot more discussion attached to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-type-narrowing Conditional type narrowing / binder
Projects
None yet
Development

No branches or pull requests

3 participants