Skip to content

Produce error when NamedTuple is assigned to attribute - #7662

Merged
JukkaL merged 4 commits into
python:masterfrom
AFanaei:namedtuple-as-attr
Oct 28, 2019
Merged

JukkaL merged 4 commits into
python:masterfrom
AFanaei:namedtuple-as-attr

Conversation

@AFanaei

@AFanaei AFanaei commented Oct 9, 2019

Copy link
Copy Markdown
Contributor

Fixes #7531

@AFanaei
AFanaei force-pushed the namedtuple-as-attr branch from fe9ac72 to 3c062be Compare October 9, 2019 06:30
Comment thread mypy/semanal.py
Comment thread mypy/semanal.py
@AFanaei

AFanaei commented Oct 11, 2019

Copy link
Copy Markdown
Contributor Author

hi @JukkaL , could you review this PR?

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Looks mostly good. I have a suggestion about tests.

Comment thread mypy/semanal.py Outdated
Comment thread mypy/semanal.py
Comment thread test-data/unit/check-namedtuple.test Outdated
@AFanaei
AFanaei force-pushed the namedtuple-as-attr branch from f8df8c9 to 6651401 Compare October 12, 2019 06:59
Comment thread test-data/unit/pythoneval.test
Comment thread mypy/semanal.py
return False
if isinstance(s.lvalues[0], MemberExpr):
self.fail("NamedTuple type as an attribute is not supported", lvalue)
return False

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this block to start but then a NamedTuple type as an attrib ... error was generated on every attribute assignment statement.
as the error should raise only if RHS is NamedTuple, i think this block is better at the end.

@AFanaei
AFanaei requested a review from JukkaL October 25, 2019 11:44

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good.

@JukkaL
JukkaL merged commit e2d2c11 into python:master Oct 28, 2019
ilevkivskyi pushed a commit that referenced this pull request Dec 9, 2019
…me for variable (#8112)

Followed the discussion in #8107 (comment), refine the code merged in #7662 by:

- move testcase from `pythoneval.test` to `check-namedtuple.test` and rename it from `testNamedTupleAtRunTime` to `testAssignNamedTupleAsAttribute`
- change `s.lvalues[0]` to `lvalue` to make it more concise
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

Successfully merging this pull request may close these issues.

NamedTuple triggered mypy error inside a class

3 participants