Skip to content

Commit ce0703a

Browse files
TH3CHARLieilevkivskyi
authored andcommitted
move testcase to proper file, change its name and use more concise name for variable (python#8112)
Followed the discussion in python#8107 (comment), refine the code merged in python#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
1 parent e8ae122 commit ce0703a

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2149,7 +2149,7 @@ def analyze_namedtuple_assign(self, s: AssignmentStmt) -> bool:
21492149
self.is_func_scope())
21502150
if not is_named_tuple:
21512151
return False
2152-
if isinstance(s.lvalues[0], MemberExpr):
2152+
if isinstance(lvalue, MemberExpr):
21532153
self.fail("NamedTuple type as an attribute is not supported", lvalue)
21542154
return False
21552155
# Yes, it's a valid namedtuple, but defer if it is not ready.

test-data/unit/check-namedtuple.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,3 +896,12 @@ reveal_type(u.field_1) # N: Revealed type is 'typing.Mapping[Tuple[builtins.int
896896
reveal_type(u.field_2) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple]'
897897
reveal_type(u[0]) # N: Revealed type is 'typing.Mapping[Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple], builtins.int]'
898898
reveal_type(u[1]) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple]'
899+
900+
[case testAssignNamedTupleAsAttribute]
901+
from typing import NamedTuple
902+
903+
class A:
904+
def __init__(self) -> None:
905+
self.b = NamedTuple('x', [('s', str), ('n', int)]) # E: NamedTuple type as an attribute is not supported
906+
907+
reveal_type(A().b) # N: Revealed type is 'Any'

test-data/unit/pythoneval.test

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,18 +1479,6 @@ def f_suppresses() -> int:
14791479
_testUnreachableWithStdlibContextManagersNoStrictOptional.py:9: error: Statement is unreachable
14801480
_testUnreachableWithStdlibContextManagersNoStrictOptional.py:15: error: Statement is unreachable
14811481

1482-
[case testNamedTupleAtRunTime]
1483-
from typing import NamedTuple
1484-
1485-
class A:
1486-
def __init__(self) -> None:
1487-
self.b = NamedTuple('x', [('s', str), ('n', int)])
1488-
1489-
reveal_type(A().b)
1490-
[out]
1491-
_testNamedTupleAtRunTime.py:5: error: NamedTuple type as an attribute is not supported
1492-
_testNamedTupleAtRunTime.py:7: note: Revealed type is 'Any'
1493-
14941482
[case testAsyncioFutureWait]
14951483
# mypy: strict-optional
14961484
from asyncio import Future, wait

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy