lint/stubgen: fix typing issues
This commit is contained in:
@@ -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".
|
||||
|
||||
Reference in New Issue
Block a user