|
20 | 20 | import string |
21 | 21 | import sys |
22 | 22 | import textwrap |
23 | | -from typing import (Any, Dict, Iterable, List, |
| 23 | +from typing import (Any, Iterable, |
24 | 24 | NamedTuple, NoReturn, Optional, |
25 | | - Set, Tuple, TYPE_CHECKING, Union) |
| 25 | + TYPE_CHECKING, Union) |
26 | 26 |
|
27 | 27 | # NOTE: tests/test_dtlib.py is the test suite for this library. |
28 | 28 |
|
@@ -92,9 +92,9 @@ def __init__(self, name: str, parent: Optional['Node'], dt: 'DT'): |
92 | 92 | # Remember to update DT.__deepcopy__() if you change this. |
93 | 93 |
|
94 | 94 | self._name = name |
95 | | - self.props: Dict[str, 'Property'] = {} |
96 | | - self.nodes: Dict[str, 'Node'] = {} |
97 | | - self.labels: List[str] = [] |
| 95 | + self.props: dict[str, Property] = {} |
| 96 | + self.nodes: dict[str, Node] = {} |
| 97 | + self.labels: list[str] = [] |
98 | 98 | self.parent = parent |
99 | 99 | self.dt = dt |
100 | 100 |
|
@@ -309,21 +309,21 @@ def __init__(self, node: Node, name: str): |
309 | 309 |
|
310 | 310 | self.name = name |
311 | 311 | self.value = b"" |
312 | | - self.labels: List[str] = [] |
| 312 | + self.labels: list[str] = [] |
313 | 313 | # We have to wait to set this until later, when we've got |
314 | 314 | # the entire tree. |
315 | | - self.offset_labels: Dict[str, int] = {} |
| 315 | + self.offset_labels: dict[str, int] = {} |
316 | 316 | self.node: Node = node |
317 | 317 |
|
318 | | - self._label_offset_lst: List[Tuple[str, int]] = [] |
| 318 | + self._label_offset_lst: list[tuple[str, int]] = [] |
319 | 319 |
|
320 | 320 | # A list of [offset, label, type] lists (sorted by offset), |
321 | 321 | # giving the locations of references within the value. 'type' |
322 | 322 | # is either _MarkerType.PATH, for a node path reference, |
323 | 323 | # _MarkerType.PHANDLE, for a phandle reference, or |
324 | 324 | # _MarkerType.LABEL, for a label on/within data. Node paths |
325 | 325 | # and phandles need to be patched in after parsing. |
326 | | - self._markers: List[List] = [] |
| 326 | + self._markers: list[list] = [] |
327 | 327 |
|
328 | 328 | @property |
329 | 329 | def type(self) -> Type: |
@@ -388,7 +388,7 @@ def to_num(self, signed=False) -> int: |
388 | 388 |
|
389 | 389 | return int.from_bytes(self.value, "big", signed=signed) |
390 | 390 |
|
391 | | - def to_nums(self, signed=False) -> List[int]: |
| 391 | + def to_nums(self, signed=False) -> list[int]: |
392 | 392 | """ |
393 | 393 | Returns the value of the property as a list of numbers. |
394 | 394 |
|
@@ -455,7 +455,7 @@ def to_string(self) -> str: |
455 | 455 |
|
456 | 456 | return ret # The separate 'return' appeases the type checker. |
457 | 457 |
|
458 | | - def to_strings(self) -> List[str]: |
| 458 | + def to_strings(self) -> list[str]: |
459 | 459 | """ |
460 | 460 | Returns the value of the property as a list of strings. |
461 | 461 |
|
@@ -498,7 +498,7 @@ def to_node(self) -> Node: |
498 | 498 |
|
499 | 499 | return self.node.dt.phandle2node[int.from_bytes(self.value, "big")] |
500 | 500 |
|
501 | | - def to_nodes(self) -> List[Node]: |
| 501 | + def to_nodes(self) -> list[Node]: |
502 | 502 | """ |
503 | 503 | Returns a list with the Nodes the phandles in the property point to. |
504 | 504 |
|
@@ -761,20 +761,20 @@ def __init__(self, filename: Optional[str], include_path: Iterable[str] = (), |
761 | 761 | # Remember to update __deepcopy__() if you change this. |
762 | 762 |
|
763 | 763 | self._root: Optional[Node] = None |
764 | | - self.alias2node: Dict[str, Node] = {} |
765 | | - self.label2node: Dict[str, Node] = {} |
766 | | - self.label2prop: Dict[str, Property] = {} |
767 | | - self.label2prop_offset: Dict[str, Tuple[Property, int]] = {} |
768 | | - self.phandle2node: Dict[int, Node] = {} |
769 | | - self.memreserves: List[Tuple[Set[str], int, int]] = [] |
| 764 | + self.alias2node: dict[str, Node] = {} |
| 765 | + self.label2node: dict[str, Node] = {} |
| 766 | + self.label2prop: dict[str, Property] = {} |
| 767 | + self.label2prop_offset: dict[str, tuple[Property, int]] = {} |
| 768 | + self.phandle2node: dict[int, Node] = {} |
| 769 | + self.memreserves: list[tuple[set[str], int, int]] = [] |
770 | 770 | self.filename = filename |
771 | 771 |
|
772 | 772 | self._force = force |
773 | 773 |
|
774 | 774 | if filename is not None: |
775 | 775 | self._parse_file(filename, include_path) |
776 | 776 | else: |
777 | | - self._include_path: List[str] = [] |
| 777 | + self._include_path: list[str] = [] |
778 | 778 |
|
779 | 779 | @property |
780 | 780 | def root(self) -> Node: |
@@ -1027,7 +1027,7 @@ def _parse_file(self, filename: str, include_path: Iterable[str]): |
1027 | 1027 | self._file_contents = f.read() |
1028 | 1028 |
|
1029 | 1029 | self._tok_i = self._tok_end_i = 0 |
1030 | | - self._filestack: List[_FileStackElt] = [] |
| 1030 | + self._filestack: list[_FileStackElt] = [] |
1031 | 1031 |
|
1032 | 1032 | self._lexer_state: int = _DEFAULT |
1033 | 1033 | self._saved_token: Optional[_Token] = None |
@@ -2027,7 +2027,7 @@ def to_num(data: bytes, length: Optional[int] = None, |
2027 | 2027 |
|
2028 | 2028 | return int.from_bytes(data, "big", signed=signed) |
2029 | 2029 |
|
2030 | | -def to_nums(data: bytes, length: int = 4, signed: bool = False) -> List[int]: |
| 2030 | +def to_nums(data: bytes, length: int = 4, signed: bool = False) -> list[int]: |
2031 | 2031 | """ |
2032 | 2032 | Like Property.to_nums(), but takes an arbitrary 'bytes' array. The values |
2033 | 2033 | are assumed to be in big-endian format, which is standard in devicetree. |
|
0 commit comments