Closed pylint-bot closed 8 years ago
Original comment by BitBucket: cezarelnazli, GitHub: @cezarelnazli?:
Hi, I created a file using the code samples from PEP 448 and ran it against pylint. I wrote the results in comments. I could add tests, but I was wondering if they should be functional or otherwise.
#!python
# these are okay
print(*[1], *[2], 3)
a = dict(**{'x': 1}, y=2, **{'z': 3})
# star-needs-assignment-target
b = (*range(4), 4)
c = [*range(4), 4]
d = {*range(4), 4}
# AttributeError: 'TreeRebuilder3' object has no attribute 'visit_nonetype'
e = {'x': 1, **{'y': 2}}
print({'x': 1, **{'x': 2}})
print({**{'x': 2}, 'x': 1})
Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):
They should be functional tests. star-needs-assignment-target is a false positive for instance. The other one doesn't ring a bell.
Original comment by BitBucket: cezarelnazli, GitHub: @cezarelnazli?:
The other one is an exception raised by astroid. Also, since those lines raise an exception, should I add them to the test?
#!python
/astroid/astroid/rebuilder.py", line 132, in visit
visit_method = getattr(self, visit_name)
AttributeError: 'TreeRebuilder3' object has no attribute 'visit_nonetype'
************* Module unpack
F: 1, 0: <class 'AttributeError'>: 'TreeRebuilder3' object has no attribute 'visit_nonetype' (astroid-error)
Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):
Okay, that makes sense. It's because an unpacking of a dict on Python 3.5 is expressed as a pair of None and the dict itself, so {'x': 1, **{'y': 2}} will have ['x', None] as keys and [1, {'y':2}] as values.
Original comment by BitBucket: cezarelnazli, GitHub: @cezarelnazli?:
I added a pull request, let me know if it needs modifying.
Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):
More tests would be nice. ;-)
Original comment by BitBucket: cezarelnazli, GitHub: @cezarelnazli?:
I added a few more for dicts, again copied from the PEP page. Let me know what else you have in mind and I'll add them.
Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):
Thanks. I created https://bitbucket.org/logilab/astroid/issues/206/crash-when-encountering-pep-448-unpacking for tracking the crash
Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):
Don't warn about Starred nodes used properly in unpacking contexts
Closes issue #653
Originally reported by: Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore)
They were added with PEP 448. We should add some tests to see what pylint catches and if we have FPs or not. Related to https://bitbucket.org/logilab/astroid/issues/201, but that issue is for understanding of these constructs, while this issue is for a more shallow interaction with them.