Skip to content

Produce error when NamedTuple is assigned to attribute #7662

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

Merged
merged 4 commits into from
Oct 28, 2019

Conversation

AFanaei
Copy link
Contributor

@AFanaei AFanaei commented Oct 9, 2019

Fixes #7531

@AFanaei AFanaei force-pushed the namedtuple-as-attr branch from fe9ac72 to 3c062be Compare October 9, 2019 06:30
@AFanaei
Copy link
Contributor Author

AFanaei commented Oct 11, 2019

hi @JukkaL , could you review this PR?

Copy link
Collaborator

@JukkaL JukkaL left a comment

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.

@AFanaei AFanaei force-pushed the namedtuple-as-attr branch from f8df8c9 to 6651401 Compare October 12, 2019 06:59
return False
lvalue = s.lvalues[0]
name = lvalue.name
is_named_tuple, info = self.named_tuple_analyzer.check_namedtuple(s.rvalue, name,
self.is_func_scope())
if not is_named_tuple:
return False
if isinstance(s.lvalues[0], MemberExpr):
self.fail("NamedTuple type as an attribute is not supported", lvalue)
return False
Copy link
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
Copy link
Collaborator

@JukkaL JukkaL left a comment

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