lint/stubgen: fix typing issues

This commit is contained in:
2026-07-09 15:54:59 +08:00
parent b335519832
commit 7156567302
11 changed files with 80 additions and 88 deletions
+9 -10
View File
@@ -1,6 +1,11 @@
"""Utility functions for capnp-stubgen."""
import os
from typing import Any
#: A dict from capnp's ``CodeGeneratorRequest.to_dict()``.
#: Keys are strings, values are arbitrary nested capnp data.
NodeDict = dict[str, Any]
def filename_to_module_name(filename: str) -> str:
@@ -14,18 +19,12 @@ def filename_to_module_name(filename: str) -> str:
return base + "_capnp"
def get_display_name(node: dict) -> str:
"""Extract the short display name from a node dict.
The node's ``displayName`` field contains a path like
``path/to/file.capnp:TypeName``. This removes the file prefix.
"""
name: str = node["displayName"]
prefix_len: int = node["displayNamePrefixLength"]
return name[prefix_len:]
def get_display_name(node: NodeDict) -> str:
"""Extract the short display name from a node dict."""
return str(node["displayName"])[int(node["displayNamePrefixLength"]):]
def get_node_kind(node: dict) -> str:
def get_node_kind(node: NodeDict) -> str:
"""Determine the kind of a node from its dict representation.
Returns one of: "file", "struct", "enum", "interface", "const", "annotation".