[rtems-central commit] Replace type comment with ":" annotation

Sebastian Huber sebh at rtems.org
Tue Jan 3 12:35:54 UTC 2023


Module:    rtems-central
Branch:    master
Commit:    68646f2b0be486e1fd119b9dd6325122ad374d21
Changeset: http://git.rtems.org/rtems-central/commit/?id=68646f2b0be486e1fd119b9dd6325122ad374d21

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Jan  3 12:07:19 2023 +0100

Replace type comment with ":" annotation

---

 generate_membench.py       |  2 +-
 rtemsspec/applconfig.py    |  4 ++--
 rtemsspec/build.py         |  4 ++--
 rtemsspec/content.py       | 10 +++++-----
 rtemsspec/glossary.py      |  4 ++--
 rtemsspec/interface.py     | 20 ++++++++++----------
 rtemsspec/interfacedoc.py  |  2 +-
 rtemsspec/items.py         | 18 +++++++++---------
 rtemsspec/membench.py      |  8 ++++----
 rtemsspec/specdoc.py       |  4 ++--
 rtemsspec/specverify.py    |  8 ++++----
 rtemsspec/transitionmap.py |  8 ++++----
 rtemsspec/validation.py    | 22 +++++++++++-----------
 specview.py                |  8 ++++----
 14 files changed, 61 insertions(+), 61 deletions(-)

diff --git a/generate_membench.py b/generate_membench.py
index d0817dfc..7b88e531 100755
--- a/generate_membench.py
+++ b/generate_membench.py
@@ -730,7 +730,7 @@ def _block(lines: Optional[str], level: int = 2) -> str:
 
 
 def _links(links: List[str]) -> str:
-    text = []  # type: List[str]
+    text: List[str] = []
     for link in links:
         if "group" in link:
             break
diff --git a/rtemsspec/applconfig.py b/rtemsspec/applconfig.py
index 78505a34..32dd8bd9 100644
--- a/rtemsspec/applconfig.py
+++ b/rtemsspec/applconfig.py
@@ -212,7 +212,7 @@ def _generate_feature(content: _ContentAdaptor, item: Item,
 
 def _get_constraints(content: _ContentAdaptor, item: Item,
                      enabled: List[str]) -> List[str]:
-    constraints = []  # type: List[str]
+    constraints: List[str] = []
     for parent in item.parents("constraint"):
         if not parent.is_enabled(enabled):
             continue
@@ -339,7 +339,7 @@ def generate(config: dict, group_uids: List[str],
     for group_config in config["groups"]:
         group = item_cache[group_config["uid"]]
         assert group.type == "interface/appl-config-group"
-        options = {}  # type: ItemMap
+        options: ItemMap = {}
         for child in group.children("interface-ingroup"):
             if child.type.startswith("interface/appl-config-option"):
                 options[child.uid] = child
diff --git a/rtemsspec/build.py b/rtemsspec/build.py
index ce468404..6fbc0f66 100644
--- a/rtemsspec/build.py
+++ b/rtemsspec/build.py
@@ -89,12 +89,12 @@ def gather_files(config: dict,
                  item_cache: ItemCache,
                  test_header: bool = True) -> List[str]:
     """ Generates a list of files form the build specification. """
-    bsps = {}  # type: BSPMap
+    bsps: BSPMap = {}
     for item in item_cache.all.values():
         if item["type"] == "build" and item["build-type"] == "bsp":
             arch_bsps = bsps.setdefault(item["arch"].strip(), {})
             arch_bsps[item["bsp"].strip()] = item
-    source_files = list(config["sources"])  # type: List[str]
+    source_files: List[str] = list(config["sources"])
     arch = config["arch"]
     bsp = config["bsp"]
     enabled = [arch, arch + "/" + bsp] + config["enabled"]
diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index 493c963c..20c0954e 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -185,7 +185,7 @@ class Content:
     # pylint: disable=too-many-instance-attributes
     # pylint: disable=too-many-public-methods
     def __init__(self, the_license: str, pop_indent_gap: bool):
-        self._lines = []  # type: List[str]
+        self._lines: List[str] = []
         self._license = the_license
         self._copyrights = Copyrights()
         self._gap = False
@@ -264,7 +264,7 @@ class Content:
             wrapper.break_long_words = False
             wrapper.break_on_hyphens = False
             wrapper.width = 79 - len(self._indent)
-            gap = []  # type: List[str]
+            gap: List[str] = []
             blocks = collections.deque(text.split("\n\n"))
             while blocks:
                 block = blocks.popleft()
@@ -545,8 +545,8 @@ class CInclude(NamedTuple):
 
 def _split_includes(
         includes: List[CInclude]) -> Tuple[Set[str], Dict[str, Set[str]]]:
-    includes_unconditional = set()  # type: Set[str]
-    includes_enabled_by = {}  # type: Dict[str, Set[str]]
+    includes_unconditional: Set[str] = set()
+    includes_enabled_by: Dict[str, Set[str]] = {}
     for inc in list(dict.fromkeys(includes)):
         if inc.enabled_by and inc.enabled_by != "1":
             try:
@@ -689,7 +689,7 @@ class CContent(Content):
 
     def _add_includes_enabled_by(self, includes: Dict[str, Set[str]],
                                  local: bool) -> None:
-        enabled_by_includes = {}  # type: Dict[str, Set[str]]
+        enabled_by_includes: Dict[str, Set[str]] = {}
         for inc, enabled_bys in iter(includes.items()):
             enabled_by_includes.setdefault(" && ".join(sorted(enabled_bys)),
                                            set()).add(inc)
diff --git a/rtemsspec/glossary.py b/rtemsspec/glossary.py
index df51acba..1396346d 100644
--- a/rtemsspec/glossary.py
+++ b/rtemsspec/glossary.py
@@ -115,7 +115,7 @@ def _generate_project_glossary(glossary: _Glossary, header: str, target: str,
 
 def _generate_document_glossary(config: dict, group_uids: List[str],
                                 glossary: _Glossary) -> None:
-    document_terms = {}  # type: ItemMap
+    document_terms: ItemMap = {}
     for path in config["rest-source-paths"]:
         _find_glossary_terms(path, document_terms, glossary)
     _resolve_glossary_terms(document_terms)
@@ -132,7 +132,7 @@ def generate(config: dict, group_uids: List[str],
     :param item_cache: The specification item cache containing the glossary
                        groups and terms.
     """
-    groups = {}  # type: ItemMap
+    groups: ItemMap = {}
     for uid, item in item_cache.all.items():
         if item.type == "glossary/group":
             groups[uid] = item
diff --git a/rtemsspec/interface.py b/rtemsspec/interface.py
index 5a45d6f3..d2bb3bf3 100644
--- a/rtemsspec/interface.py
+++ b/rtemsspec/interface.py
@@ -45,7 +45,7 @@ GetLines = Callable[["Node", Item, Any], Lines]
 
 
 def _get_ingroups(item: Item) -> ItemMap:
-    ingroups = {}  # type: ItemMap
+    ingroups: ItemMap = {}
     for group in item.parents("interface-ingroup"):
         ingroups[group.uid] = group
     return ingroups
@@ -230,8 +230,8 @@ class Node:
         self.header_file = header_file
         self.item = item
         self.ingroups = _get_ingroups(item)
-        self.dependents = set()  # type: Set["Node"]
-        self.depends_on = set()  # type: Set["Node"]
+        self.dependents: Set[Node] = set()
+        self.depends_on: Set[Node] = set()
         self.content = CContent()
         self.mapper = _InterfaceMapper(self)
         try:
@@ -292,7 +292,7 @@ class Node:
     def generate_enum(self) -> None:
         """ Generates an enum. """
         with self._enum_struct_or_union():
-            enumerators = []  # type: List[CContent]
+            enumerators: List[CContent] = []
             for parent in self.item.parents("interface-enumerator"):
                 enumerator = self._get_description(parent, {})
                 enumerator.append(
@@ -719,8 +719,8 @@ class _HeaderFile:
         self._content = CContent()
         self._content.register_license_and_copyrights_of_item(item)
         self._ingroups = _get_ingroups(item)
-        self._includes = []  # type: List[Item]
-        self._nodes = {}  # type: Dict[str, Node]
+        self._includes: List[Item] = []
+        self._nodes: Dict[str, Node] = {}
         self.enabled_by_defined = enabled_by_defined
         self.enabled = enabled
 
@@ -763,15 +763,15 @@ class _HeaderFile:
         do this, however, if you experience run time problems due to this
         method, then maybe you should reconsider your header file organization.
         """
-        nodes_in_dependency_order = []  # type: List[Node]
+        nodes_in_dependency_order: List[Node] = []
 
         # Get incoming edge degrees for all nodes
-        in_degree = {}  # type: Dict[str, int]
+        in_degree: Dict[str, int] = {}
         for node in self._nodes.values():
             in_degree[node.item.uid] = len(node.dependents)
 
         # Create a queue with all nodes with no incoming edges
-        queue = []  # type: List[Node]
+        queue: List[Node] = []
         for node in sorted(self._nodes.values()):
             if in_degree[node.item.uid] == 0:
                 queue.append(node)
@@ -838,7 +838,7 @@ def _generate_header_file(item: Item, domains: Dict[str, str],
 
 def _gather_enabled_by_defined(item_level_interfaces: List[str],
                                item_cache: ItemCache) -> Dict[str, str]:
-    enabled_by_defined = {}  # type: Dict[str, str]
+    enabled_by_defined: Dict[str, str] = {}
     for uid in item_level_interfaces:
         for child in item_cache[uid].children("interface-ingroup"):
             if child.type == "interface/unspecified-define":
diff --git a/rtemsspec/interfacedoc.py b/rtemsspec/interfacedoc.py
index b4507789..9474d353 100644
--- a/rtemsspec/interfacedoc.py
+++ b/rtemsspec/interfacedoc.py
@@ -219,7 +219,7 @@ def generate(config: dict, item_cache: ItemCache) -> None:
     enabled = config["enabled"]
     group_uids = [doc_config["group"] for doc_config in groups]
     for doc_config in groups:
-        items = []  # type: List[Item]
+        items: List[Item] = []
         group = item_cache[doc_config["group"]]
         assert group.type == "interface/group"
         for child in group.children("interface-ingroup"):
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index b6278e8a..7e116075 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -188,8 +188,8 @@ class Item:
         self._cache = item_cache
         self._uid = uid
         self._data = data
-        self._links_to_parents = []  # type: List[Link]
-        self._links_to_children = []  # type: List[Link]
+        self._links_to_parents: List[Link] = []
+        self._links_to_children: List[Link] = []
 
     def __eq__(self, other: Any) -> bool:
         if not isinstance(other, Item):
@@ -486,7 +486,7 @@ class ItemMapper:
         self._item = item
         self._recursive = recursive
         self._prefix = [""]
-        self._get_value_map = {}  # type: Dict[str, ItemGetValueMap]
+        self._get_value_map: Dict[str, ItemGetValueMap] = {}
 
     @property
     def item(self) -> Item:
@@ -622,7 +622,7 @@ class _SpecType(NamedTuple):
 
 
 def _gather_spec_refinements(item: Item) -> Optional[_SpecType]:
-    new_type = None  # type: Optional[_SpecType]
+    new_type: Optional[_SpecType] = None
     for link in item.links_to_children():
         if link.role == "spec-refinement":
             key = link["spec-key"]
@@ -667,9 +667,9 @@ class ItemCache:
                  config: Any,
                  post_process_load: Optional[Callable[[ItemMap],
                                                       None]] = None):
-        self._items = {}  # type: ItemMap
-        self._types = set()  # type: Set[str]
-        self.items_by_type = {}  # type: Dict[str, List[Item]]
+        self._items: ItemMap = {}
+        self._types: Set[str] = set()
+        self.items_by_type: Dict[str, List[Item]] = {}
         self._updates = 0
         self._load_items(config)
         if post_process_load:
@@ -732,7 +732,7 @@ class ItemCache:
 
     def _load_items_in_dir(self, base: str, path: str, cache_file: str,
                            update_cache: bool) -> None:
-        data_by_uid = {}  # type: Dict[str, Any]
+        data_by_uid: Dict[str, Any] = {}
         if update_cache:
             self._updates += 1
             for name in os.listdir(path):
@@ -804,7 +804,7 @@ class ItemCache:
     def _set_type(self, item: Item) -> None:
         spec_type = self._root_type
         value = item.data
-        path = []  # type: List[str]
+        path: List[str] = []
         while spec_type is not None:
             type_name = value[spec_type.key]
             path.append(type_name)
diff --git a/rtemsspec/membench.py b/rtemsspec/membench.py
index 598ac4f0..d7a554b5 100644
--- a/rtemsspec/membench.py
+++ b/rtemsspec/membench.py
@@ -86,7 +86,7 @@ def _do_gather_test_suites(items: List[Item], item: Item) -> None:
 
 def gather_benchmarks(root: Item) -> List[Item]:
     """ Gather all test suite items related to the root item. """
-    items = []  # type: List[Item]
+    items: List[Item] = []
     _do_gather_test_suites(items, root)
     return items
 
@@ -100,10 +100,10 @@ def get_path_to_test_suite_elf_file(item: Item, path: str) -> str:
 
 def _get_sections(item: Item, path: str) -> Dict[str, Tuple[int, int]]:
     elf = get_path_to_test_suite_elf_file(item, path)
-    stdout = []  # type: List[str]
+    stdout: List[str] = []
     status = run_command(["objdump", "-h", elf], stdout=stdout)
     assert status == 0
-    sections = {}  # type: Dict[str, Tuple[int, int]]
+    sections: Dict[str, Tuple[int, int]] = {}
     for line in stdout:
         match = _SECTION.search(line)
         if match:
@@ -124,7 +124,7 @@ def _get_label(item: Item) -> str:
 
 def _generate_table(content: SphinxContent, items: List[Item],
                     path: str) -> None:
-    rows = []  # type: List[Tuple[str, ...]]
+    rows: List[Tuple[str, ...]] = []
     for index, item in enumerate(items):
         sections = _get_sections(item, path)
         name = (get_reference(_get_label(item), item.uid), )
diff --git a/rtemsspec/specdoc.py b/rtemsspec/specdoc.py
index ee1f3090..658da477 100644
--- a/rtemsspec/specdoc.py
+++ b/rtemsspec/specdoc.py
@@ -264,7 +264,7 @@ class _Documenter:
         self._info_map = item["spec-info"]
         self._item = item
         self._documenter_map = documenter_map
-        self.used_by = set()  # type: Set[str]
+        self.used_by: Set[str] = set()
         self._label_prefix = config["label-prefix"]
         self._mapper = SphinxMapper(item)
         self._mapper.add_get_value("spec:/spec-name",
@@ -540,7 +540,7 @@ def document(config: dict, item_cache: ItemCache) -> None:
     :param config: A dictionary with configuration entries.
     :param item_cache: The specification item cache.
     """
-    documenter_map = {}  # type: _DocumenterMap
+    documenter_map: _DocumenterMap = {}
     root_item = item_cache[config["root-type"]]
     _create_str_documenter(
         item_cache, "Name", "A string is a valid name if it matches with the "
diff --git a/rtemsspec/specverify.py b/rtemsspec/specverify.py
index 50c576d8..7bf94f7d 100755
--- a/rtemsspec/specverify.py
+++ b/rtemsspec/specverify.py
@@ -47,7 +47,7 @@ class _Filter(logging.Filter):
 
     def __init__(self):
         super().__init__()
-        self._counts = {}  # type: Dict[int, int]
+        self._counts: Dict[int, int] = {}
 
     def filter(self, record: logging.LogRecord) -> bool:
         count = self._counts.get(record.levelno, 0)
@@ -283,7 +283,7 @@ class _ItemVerifier(_Verifier):
         self._info_map = info_map
         self._item = item
         self._subtype_key = ""
-        self._subtype_verifiers = {}  # type: _VerifierMap
+        self._subtype_verifiers: _VerifierMap = {}
 
     def verify_bool(self, path: _Path, value: Any, type_info: Any) -> Set[str]:
         """ Verifies a boolean value. """
@@ -361,7 +361,7 @@ class _ItemVerifier(_Verifier):
         keys = sorted(filter(lambda key: not key.startswith("_"), value))
         attr_info = type_info["attributes"]
         self._assert_mandatory_keys(path, type_info, attr_info, keys)
-        verified_keys = set()  # type: Set[str]
+        verified_keys: Set[str] = set()
         for key in keys:
             if key in attr_info:
                 self._verify_key(path, value, attr_info[key]["spec-type"], key)
@@ -501,7 +501,7 @@ class SpecVerifier:
 
     # pylint: disable=too-few-public-methods
     def __init__(self, item_cache: ItemCache, root_uid: str):
-        verifier_map = {}  # type: _VerifierMap
+        verifier_map: _VerifierMap = {}
         _AnyVerifier("any", verifier_map)
         _NameVerifier("name", verifier_map)
         _UIDVerifier("uid", verifier_map)
diff --git a/rtemsspec/transitionmap.py b/rtemsspec/transitionmap.py
index cdb8d27a..77c080f1 100644
--- a/rtemsspec/transitionmap.py
+++ b/rtemsspec/transitionmap.py
@@ -56,7 +56,7 @@ class _TransitionEntry:
 
     def __init__(self):
         self.key = ""
-        self.variants = []  # type: List[Transition]
+        self.variants: List[Transition] = []
 
     def __bool__(self):
         return bool(self.variants)
@@ -288,7 +288,7 @@ class TransitionMap:
         self._skip_name_to_idx = dict(
             (key, skip_idx + 1)
             for skip_idx, key in enumerate(item["skip-reasons"].keys()))
-        self._entries = {}  # type: Dict[str, List[Any]]
+        self._entries: Dict[str, List[Any]] = {}
         self._map = self._build_map()
         self._post_process()
 
@@ -329,7 +329,7 @@ class TransitionMap:
         pre-condition and provides a list of corresponding pre-condition state
         indices.
         """
-        entries = {}  # type: Dict[PostCond, PreCondsOfPostCond]
+        entries: Dict[PostCond, PreCondsOfPostCond] = {}
         for map_idx, variant in self.get_variants(enabled):
             key = (variant.skip, ) + variant.post_cond
             entry = entries.setdefault(key, [])
@@ -652,7 +652,7 @@ class TransitionMap:
                 entries.append(self._get_entry(ident, transitions[0]))
             else:
                 ifelse = "#if "
-                enumerators = []  # type: List[str]
+                enumerators: List[str] = []
                 for variant in transitions[1:]:
                     enumerators.append(
                         ifelse + enabled_by_to_exp(variant.enabled_by, mapper))
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index 37dba747..2bf5384b 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -537,7 +537,7 @@ class _ActionRequirementTestItem(_TestItem):
         self._mapper.add_get_value(("requirement/functional/action:"
                                     "/pre-conditions/states/test-code/skip"),
                                    self._skip_pre_condition)
-        self._pre_co_skip = {}  # type: Dict[int, bool]
+        self._pre_co_skip: Dict[int, bool] = {}
         self._pre_co_count = len(item["pre-conditions"])
         self._pre_co_idx_to_enum = _to_enum(f"{self.ident}_Pre",
                                             item["pre-conditions"])
@@ -1026,8 +1026,8 @@ class _SourceFile:
     def __init__(self, filename: str):
         """ Initializes a test source file. """
         self._file = filename
-        self._test_suites = []  # type: List[_TestItem]
-        self._test_cases = []  # type: List[_TestItem]
+        self._test_suites: List[_TestItem] = []
+        self._test_cases: List[_TestItem] = []
 
     @property
     def test_suites(self) -> List[_TestItem]:
@@ -1061,8 +1061,8 @@ class _SourceFile:
         Generates the source file and the corresponding build specification.
         """
         content = CContent()
-        includes = []  # type: List[CInclude]
-        local_includes = []  # type: List[CInclude]
+        includes: List[CInclude] = []
+        local_includes: List[CInclude] = []
         for item in itertools.chain(self._test_suites, self._test_cases):
             includes.extend(map(CInclude, item.includes))
             local_includes.extend(map(CInclude, item.local_includes))
@@ -1096,8 +1096,8 @@ class _TestProgram:
     def __init__(self, item: Item):
         """ Initializes a test program. """
         self._item = item
-        self._source_files = []  # type: List[_SourceFile]
-        self._build_source_files = []  # type: List[str]
+        self._source_files: List[_SourceFile] = []
+        self._build_source_files: List[str] = []
         _gather_build_source_files(item, self._build_source_files)
 
     @property
@@ -1169,16 +1169,16 @@ _GATHER = {
 
 def _gather(
         item_cache: ItemCache) -> Tuple[Dict[str, _SourceFile], _CaseToSuite]:
-    source_files = {}  # type: Dict[str, _SourceFile]
-    test_programs = []  # type: List[_TestProgram]
+    source_files: Dict[str, _SourceFile] = {}
+    test_programs: List[_TestProgram] = []
     for item in item_cache.all.values():
         _GATHER.get(item.type, _gather_default)(item, source_files,
                                                 test_programs)
 
-    test_case_to_suites = {}  # type: _CaseToSuite
+    test_case_to_suites: _CaseToSuite = {}
     for test_program in test_programs:
         test_program.add_source_files(source_files)
-        test_suites = []  # type: List[_TestItem]
+        test_suites: List[_TestItem] = []
         for source_file in test_program.source_files:
             test_suites.extend(source_file.test_suites)
         for source_file in test_program.source_files:
diff --git a/specview.py b/specview.py
index a7ba8a67..e6ee5bb8 100755
--- a/specview.py
+++ b/specview.py
@@ -262,10 +262,10 @@ def _design(item_cache: ItemCache, enabled: List[str]) -> None:
     for item in item_cache.all.values():
         if not item.is_enabled(enabled):
             continue
-        components = []  # type: List[Item]
+        components: List[Item] = []
         if not _gather_design_components(item, components):
             continue
-        compact = set()  # type: Set[Item]
+        compact: Set[Item] = set()
         for component in components:
             for component_2 in components:
                 if component != component_2:
@@ -339,7 +339,7 @@ def _action_list(enabled: List[str], item: Item) -> None:
         if post_cond[0]:
             print(transition_map.skip_idx_to_name(post_cond[0]))
         else:
-            names = []  # type: List[str]
+            names: List[str] = []
             for co_idx, st_idx in enumerate(post_cond[1:]):
                 st_name = transition_map.post_co_idx_st_idx_to_st_name(
                     co_idx, st_idx)
@@ -390,7 +390,7 @@ def _gather_api_names(item: Item, names: Dict[str, List[str]]) -> None:
 
 
 def _list_api(item_cache: ItemCache) -> None:
-    names = {}  # type: Dict[str, List[str]]
+    names: Dict[str, List[str]] = {}
     _gather_api_names(item_cache["/req/applconfig"], names)
     _gather_api_names(item_cache["/if/group"], names)
     _gather_api_names(item_cache["/c/if/group"], names)



More information about the vc mailing list