-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Treat underscore variables as anonymous #3125
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
Conversation
test-data/unit/check-basic.test
Outdated
(_, _) = (1.0, "") | ||
for (_, _) in ((1, "a"), (2, "b")): pass | ||
|
||
def f(_: int, _: str) -> None: pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually gives SyntaxError: duplicate argument '_' in function definition
at runtime (also in Python 2 with annotations removed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops :) thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see few problems with this PR:
- you mention "fix Allow
Any
types for tuple except handler tests #1639" in the PR description, but this seems to be a typo, the mentioned PR seems to be unrelated. - We probably should not drop all type checking for variables named
_
, the reason is that it is frequently used forgettext
and i18n. Possible solutions would be to only drop type checking if_
variable is never read, see Type error due to repeated use of underscore as dummy assignment target #465, or maybe keep type checking_
if it has an explicitly declared type. - this needs to be documented.
Thanks. I have fixed the issue reference. |
There are some ideas in #1332. I will give it some thought. |
Since we want to continue the usage of |
Ok. |
Fix
#1639#1649: allow(_, _) = (1, "")
There's no test for usage of underscores. I don't know how to define when and where this is legal (although pretty common in some frameworks)