[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

/ mypy Public

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

Merged
merged 1 commit into from Dec 12, 2019
Merged

Produce error when assigning Enum or TypedDict as attribute #8107

merged 1 commit into from Dec 12, 2019

Conversation

Copy link
Collaborator

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:

mypy/mypy/semanal.py

Lines 2152 to 2154 in e8ae122

if isinstance(s.lvalues[0], MemberExpr):
self.fail("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)])
reveal_type(A().b)
[out]
_testNamedTupleAtRunTime.py:5: error: NamedTuple type as an attribute is not supported
_testNamedTupleAtRunTime.py:7: 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.

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 pushed a commit that referenced this issue 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
Collaborator

msullivan left a comment

This seems reasonable. Thanks!

msullivan merged commit a2ab97b into python:master Dec 12, 2019
2 checks passed
TH3CHARLie deleted the 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants