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

Handle literal value with parameter tuple that has parentheses #707

Closed
Glyphack opened this issue Nov 7, 2023 · 1 comment
Closed

Handle literal value with parameter tuple that has parentheses #707

Glyphack opened this issue Nov 7, 2023 · 1 comment

Comments

@Glyphack
Copy link

Glyphack commented Nov 7, 2023

According to typing spec tuple value inside a Literal type annotation is not allowed.

while I was playing around in #706 with it If found that the Literal value with a tuple parameter is treated the same with and without parentheses.

Is this intended behavior?

By the way Python ast parses these two expressions the same so finding out this would be difficult:

>>> print(ast.dump(ast.parse("s[(0,0)]")))
Module(body=[Expr(value=Subscript(value=Name(id='s', ctx=Load()), slice=Tuple(elts=[Constant(value=0), Constant(value=0)], ctx=Load()), ctx=Load()))], type_ignores=[])
>>> print(ast.dump(ast.parse("s[0,0]")))
Module(body=[Expr(value=Subscript(value=Name(id='s', ctx=Load()), slice=Tuple(elts=[Constant(value=0), Constant(value=0)], ctx=Load()), ctx=Load()))], type_ignores=[])

Does it worth to open an issue on Python repo about this?

@JelleZijlstra
Copy link
Contributor

As you say, this is difficult to fix in pyanalyze because the AST doesn't distinguish between these cases. I'm personally not too bothered by this problem so I'm unlikely to introduce any new complexity to deal with it.

Possibly the Python AST could be changed to distinguish these cases, but I'm not sure that's likely. Before you open a CPython issue, I'd recommend coming up with a concrete proposal for what the AST should look like in both cases.

Closing as there's nothing here for pyanalyze to change.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2023
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

No branches or pull requests

2 participants