Skip to content

"Incompatible types in assignment" when using _ as throwaway variable #2982

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

Closed
vors opened this issue Mar 8, 2017 · 4 comments
Closed

"Incompatible types in assignment" when using _ as throwaway variable #2982

vors opened this issue Mar 8, 2017 · 4 comments
Labels

Comments

@vors
Copy link

vors commented Mar 8, 2017

Should _ get a special treatment?

Repro

import os

for _ in range(3): # throw-away _
    root, _ = os.path.split("C:\\123") # throw-away _

Expected

No errors

Actual

foo.py:4: error: Incompatible types in assignment (expression has type "str", variable has type "int")
@gvanrossum
Copy link
Member

It's been proposed before, there may even be an open issue for it already, but GitHub can't seem to search for "_". If someone submits a PR I'm happy to review it.

@vors
Copy link
Author

vors commented Mar 8, 2017

Oh, sorry I didn't search extensively before filling.

I aslo tried to work-around it with

import os
from typing import Any

for _ in range(3):  # type: Any
    root, _ = os.path.split("C:\\123")

And that produces foo.py:4: error: Parse error before "Any" which seems like a separate issue.

@gvanrossum
Copy link
Member

gvanrossum commented Mar 8, 2017 via email

@ilevkivskyi
Copy link
Member

Here is the issue that Guido mentioned #465.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants