From 757a467be8eb1ccbacb7f21c65a0efe8913b697e Mon Sep 17 00:00:00 2001 From: TH3CHARLie Date: Mon, 9 Dec 2019 11:26:50 +0800 Subject: [PATCH] move testcase to proper file, change its name and use more concise name for variable --- mypy/semanal.py | 2 +- test-data/unit/check-namedtuple.test | 9 +++++++++ test-data/unit/pythoneval.test | 12 ------------ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index f1fb8ff8be93..8d5eef752a2d 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -2149,7 +2149,7 @@ def analyze_namedtuple_assign(self, s: AssignmentStmt) -> bool: self.is_func_scope()) if not is_named_tuple: return False - if isinstance(s.lvalues[0], MemberExpr): + if isinstance(lvalue, MemberExpr): self.fail("NamedTuple type as an attribute is not supported", lvalue) return False # Yes, it's a valid namedtuple, but defer if it is not ready. diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index ab5c7bd0b6bb..e19589fba35d 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -896,3 +896,12 @@ reveal_type(u.field_1) # N: Revealed type is 'typing.Mapping[Tuple[builtins.int reveal_type(u.field_2) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple]' reveal_type(u[0]) # N: Revealed type is 'typing.Mapping[Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple], builtins.int]' reveal_type(u[1]) # N: Revealed type is 'Tuple[builtins.int, builtins.int, fallback=__main__.MyBaseTuple]' + +[case testAssignNamedTupleAsAttribute] +from typing import NamedTuple + +class A: + def __init__(self) -> None: + self.b = NamedTuple('x', [('s', str), ('n', int)]) # E: NamedTuple type as an attribute is not supported + +reveal_type(A().b) # N: Revealed type is 'Any' diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index d6df7ece9899..7cda44c4e569 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -1479,18 +1479,6 @@ def f_suppresses() -> int: _testUnreachableWithStdlibContextManagersNoStrictOptional.py:9: error: Statement is unreachable _testUnreachableWithStdlibContextManagersNoStrictOptional.py:15: error: Statement is unreachable -[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' - [case testAsyncioFutureWait] # mypy: strict-optional from asyncio import Future, wait 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