question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

False positive generalized unpacking detection with starred expression as assignment target

See original GitHub issue

Starred expressions are allowed as assignment targets for Python < 3.5:

root@f1b4a742d8fc:/# python3.4
Python 3.4.10 (default, Mar 29 2019, 18:50:06)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> *x, y = [1, 2, 3]
>>> x
[1, 2]
>>> y
3
>>> z = *x, y
  File "<stdin>", line 1
SyntaxError: can use starred expression only as assignment target

Currently vermin falsely report this case as 3.5+:

>>> vermin.detect('*x, y = [1, 2, 3]')
[None, (3, 5)]

Maybe we need to mark some flags such as self.__seen_assign_target in visit_Assign and treat the targets attribute specially.

Environment

  • Vermin version 1.0.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
gousaiyangcommented, Nov 19, 2020

Three issues:

  1. Assignment target with starred expression could also appear at for loops and comprehensions:
for *x, in [[1]]: pass
[x for *x, in [[1]]]  # also dict, set, generator comprehensions
  1. Starred items may be deeply nested (not just direct child nodes as processed by ast.iter_child_nodes):
([x, *y], z) = ((1, 2), 3)
  1. Suppressing detection for assignment targets also incorrectly suppressed detection for the expression part (right value):
*x, y = *u, *v
0reactions
netromdkcommented, Nov 20, 2020

Great. It’s merged. Thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unpacking with starred assignments | Pydon't - Mathspp
A Python code snippet unpacking a list with starred assignment. (If you are new here and have no idea what a Pydon't is,...
Read more >
Why is this unpacking expression not allowed in python3.10?
There's an official discussion here. The most relevant quote I can find is: Also the current behavior allows (*x), y = 1 assignment....
Read more >
Broken on Python 3.4: SyntaxError: can use starred ... - GitHub
If I run dazel==0.0.33 I get the following error: > virtualenv -p python3 env > env/bin/python3 --version Python 3.4.3 > env/bin/pip install ...
Read more >
star-needs-assignment-target / E0114 - Pylint 2.16.0-dev ...
Can use starred expression only in assignment target. Description: Emitted when a star expression is not used in an assignment target. Problematic code:....
Read more >
Pylint Documentation - Read the Docs
Pylint tries hard to report as few false positives as possible for errors ... when a star expression is used as a starred...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found