@@ -41,7 +41,8 @@ def __init__(self, options: Options, api: SemanticAnalyzerInterface) -> None:
41
41
self .options = options
42
42
self .api = api
43
43
44
- def analyze_namedtuple_classdef (self , defn : ClassDef ) -> Tuple [bool , Optional [TypeInfo ]]:
44
+ def analyze_namedtuple_classdef (self , defn : ClassDef , is_stub_file : bool
45
+ ) -> Tuple [bool , Optional [TypeInfo ]]:
45
46
"""Analyze if given class definition can be a named tuple definition.
46
47
47
48
Return a tuple where first item indicates whether this can possibly be a named tuple,
@@ -52,7 +53,7 @@ def analyze_namedtuple_classdef(self, defn: ClassDef) -> Tuple[bool, Optional[Ty
52
53
if isinstance (base_expr , RefExpr ):
53
54
self .api .accept (base_expr )
54
55
if base_expr .fullname == 'typing.NamedTuple' :
55
- result = self .check_namedtuple_classdef (defn )
56
+ result = self .check_namedtuple_classdef (defn , is_stub_file )
56
57
if result is None :
57
58
# This is a valid named tuple, but some types are incomplete.
58
59
return True , None
@@ -68,8 +69,10 @@ def analyze_namedtuple_classdef(self, defn: ClassDef) -> Tuple[bool, Optional[Ty
68
69
# This can't be a valid named tuple.
69
70
return False , None
70
71
71
- def check_namedtuple_classdef (
72
- self , defn : ClassDef ) -> Optional [Tuple [List [str ], List [Type ], Dict [str , Expression ]]]:
72
+ def check_namedtuple_classdef (self , defn : ClassDef , is_stub_file : bool
73
+ ) -> Optional [Tuple [List [str ],
74
+ List [Type ],
75
+ Dict [str , Expression ]]]:
73
76
"""Parse and validate fields in named tuple class definition.
74
77
75
78
Return a three tuple:
@@ -78,7 +81,7 @@ def check_namedtuple_classdef(
78
81
* field default values
79
82
or None, if any of the types are not ready.
80
83
"""
81
- if self .options .python_version < (3 , 6 ):
84
+ if self .options .python_version < (3 , 6 ) and not is_stub_file :
82
85
self .fail ('NamedTuple class syntax is only supported in Python 3.6' , defn )
83
86
return [], [], {}
84
87
if len (defn .base_type_exprs ) > 1 :
0 commit comments