Skip to content

Commit 8ba8016

Browse files
committed
NamedTuples
1 parent 7c6faf4 commit 8ba8016

File tree

6 files changed

+39
-41
lines changed

6 files changed

+39
-41
lines changed

mypy/fswatcher.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from typing import AbstractSet, Dict, Iterable, List, NamedTuple, Optional, Set, Tuple
55

66

7-
FileData = NamedTuple('FileData', [('st_mtime', float),
8-
('st_size', int),
9-
('hash', str)])
7+
class FileData(NamedTuple):
8+
st_mtime: float
9+
st_size: int
10+
hash: str
1011

1112

1213
class FileSystemWatcher:

mypy/modulefinder.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,11 @@
3030

3131

3232
# Paths to be searched in find_module().
33-
SearchPaths = NamedTuple(
34-
'SearchPaths',
35-
[
36-
('python_path', Tuple[str, ...]), # where user code is found
37-
('mypy_path', Tuple[str, ...]), # from $MYPYPATH or config variable
38-
('package_path', Tuple[str, ...]), # from get_site_packages_dirs()
39-
('typeshed_path', Tuple[str, ...]), # paths in typeshed
40-
]
41-
)
33+
class SearchPaths(NamedTuple):
34+
python_path: Tuple[str, ...] # where user code is found
35+
mypy_path: Tuple[str, ...] # from $MYPYPATH or config variable
36+
package_path: Tuple[str, ...] # from get_site_packages_dirs()
37+
typeshed_path: Tuple[str, ...] # paths in typeshed
4238

4339

4440
# Package dirs are a two-tuple of path to search and whether to verify the module

mypyc/ir/class_ir.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@
6969
# The 'shadow_method', if present, contains the method that should be
7070
# placed in the class's shadow vtable (if it has one).
7171

72-
VTableMethod = NamedTuple(
73-
'VTableMethod', [('cls', 'ClassIR'),
74-
('name', str),
75-
('method', FuncIR),
76-
('shadow_method', Optional[FuncIR])])
72+
class VTableMethod(NamedTuple):
73+
cls: 'ClassIR'
74+
name: str
75+
method: FuncIR
76+
shadow_method: Optional[FuncIR]
7777

7878

7979
VTableEntries = List[VTableMethod]

mypyc/ir/ops.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,5 +1449,6 @@ def visit_keep_alive(self, op: KeepAlive) -> T:
14491449
#
14501450
# (Serialization and deserialization *will* be used for incremental
14511451
# compilation but so far it is not hooked up to anything.)
1452-
DeserMaps = NamedTuple('DeserMaps',
1453-
[('classes', Dict[str, 'ClassIR']), ('functions', Dict[str, 'FuncIR'])])
1452+
class DeserMaps(NamedTuple):
1453+
classes: Dict[str, 'ClassIR']
1454+
functions: Dict[str, 'FuncIR']

mypyc/primitives/int_ops.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ def int_unary_op(name: str, c_function_name: str) -> CFunctionDescription:
135135
# c_func_description: the C function to call when operands are tagged integers
136136
# c_func_negated: whether to negate the C function call's result
137137
# c_func_swap_operands: whether to swap lhs and rhs when call the function
138-
IntComparisonOpDescription = NamedTuple(
139-
'IntComparisonOpDescription', [('binary_op_variant', int),
140-
('c_func_description', CFunctionDescription),
141-
('c_func_negated', bool),
142-
('c_func_swap_operands', bool)])
138+
class IntComparisonOpDescription(NamedTuple):
139+
binary_op_variant: int
140+
c_func_description: CFunctionDescription
141+
c_func_negated: bool
142+
c_func_swap_operands: bool
143143

144144

145145
# Equals operation on two boxed tagged integers

mypyc/primitives/registry.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@
4646
ERR_NEG_INT: Final = 10
4747

4848

49-
CFunctionDescription = NamedTuple(
50-
'CFunctionDescription', [('name', str),
51-
('arg_types', List[RType]),
52-
('return_type', RType),
53-
('var_arg_type', Optional[RType]),
54-
('truncated_type', Optional[RType]),
55-
('c_function_name', str),
56-
('error_kind', int),
57-
('steals', StealsDescription),
58-
('is_borrowed', bool),
59-
('ordering', Optional[List[int]]),
60-
('extra_int_constants', List[Tuple[int, RType]]),
61-
('priority', int)])
49+
class CFunctionDescription(NamedTuple):
50+
name: str
51+
arg_types: List[RType]
52+
return_type: RType
53+
var_arg_type: Optional[RType]
54+
truncated_type: Optional[RType]
55+
c_function_name: str
56+
error_kind: int
57+
steals: StealsDescription
58+
is_borrowed: bool
59+
ordering: Optional[List[int]]
60+
extra_int_constants: List[Tuple[int, RType]]
61+
priority: int
6262

6363

6464
# A description for C load operations including LoadGlobal and LoadAddress
65-
LoadAddressDescription = NamedTuple(
66-
'LoadAddressDescription', [('name', str),
67-
('type', RType),
68-
('src', str)]) # name of the target to load
65+
class LoadAddressDescription(NamedTuple):
66+
name: str
67+
type: RType
68+
src: str # name of the target to load
6969

7070

7171
# CallC op for method call(such as 'str.join')

0 commit comments

Comments
 (0)