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

Produce error when assigning Enum or TypedDict as attribute #8107



Copy link

TH3CHARLie commented Dec 8, 2019

resolves #8009, simply following solution by #7662

Additionally, when I was finishing the first version of the PR I noticed that some of #7662 could be refined:


Lines 2152 to 2154 in e8ae122

if isinstance(s.lvalues[0], MemberExpr):"NamedTuple type as an attribute is not supported", lvalue)
return False

Here using lvalue instead of s.lvalues[0] would be more concise.
[case testNamedTupleAtRunTime]
from typing import NamedTuple
class A:
def __init__(self) -> None:
self.b = NamedTuple('x', [('s', str), ('n', int)])
[out] error: NamedTuple type as an attribute is not supported note: Revealed type is 'Any'

The test is in pythoneval.test, but it makes more sense in check-namedtuple.test and the name could be also changed accordingly.

@ilevkivskyi What's your opinion on this? Should these changes be made? And if so, should they be made in this PR or a sperate one.


This comment has been minimized.

Copy link

ilevkivskyi commented Dec 8, 2019

Should these changes be made? And if so, should they be made in this PR or a sperate one.

Yes, I think in a separate PR.

ilevkivskyi added 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
Copy link

msullivan left a comment

This seems reasonable. Thanks!

@msullivan msullivan merged commit a2ab97b into python:master Dec 12, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
@TH3CHARLie TH3CHARLie deleted the TH3CHARLie:error-when-enum-or-typeddict-as-attr branch Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.