Skip to content

Typings Suite#

This suite is meant to assist in typing and type checking for the companies-house-codegen package.

generate_cli_ns #

Generator for CLINamespace.

Functions:

Name Description
dump_struct_signature

Used for testing the signature of :class:companies_house_codegen.argument.CLINamespace.

generate_namespace_typing

Generates a typed namespace class for a given argparser.

dump_struct_signature #

dump_struct_signature(cls: type) -> str

Used for testing the signature of :class:companies_house_codegen.argument.CLINamespace.

generate_namespace_typing #

generate_namespace_typing(argparser: ArgumentParser, name: str, *, type_aliases: Iterable[tuple[type[Any], str]] | None = None, default_aliases: Iterable[tuple[Any, str]] | None = None, description: str | None = None) -> str

Generates a typed namespace class for a given argparser.

Parameters:

Name Type Description Default

argparser #

ArgumentParser

the argparser whose namespace is to be produced

required

name #

str

name of newly created namespace

required

type_aliases #

Iterable[tuple[type[Any], str]] | None

aliases Action.type to one type to an arbitrary string representation

None

default_aliases #

Iterable[tuple[Any, str]] | None

aliases a Action.default value to an arbitrary string representation

None

description #

str | None

description of namespace In Numpydoc style, this corresponds to the short summary<https://numpydoc.readthedocs.io/en/latest/format.html#short-summary>, deprecation warning<https://numpydoc.readthedocs.io/en/latest/format.html#short-summary>, and extended summary<https://numpydoc.readthedocs.io/en/latest/format.html#extended-summary>_ sections.

None

Examples:

This was used to generate companies_house_codegen.argument.CLINamespace<https://mmurape.github.io/companies-house-codegen/api-reference/argument/#companies_house_codegen.argument.CLINamespace>_

>>> import sys
... from companies_house_codegen.argument import CLIArgumentParser
... from companies_house_codegen.constants import ReFormatFlags
... from tests.typings_suite.generate_cli_ns import generate_namespace_typing
... ns_typing = generate_namespace_typing(
...     CLIArgumentParser(), 'CLINamespace',
...     default_aliases=[
...         (sys.stdout, 'sys.stdout'),
...         (tuple(ReFormatFlags), '('+', '.join(str(f) for f in ReFormatFlags)+')')
...     ],
...     description="Typings for namespace of `companies-house-codegen` "
...                 "command-line interface."
... )
... print(ns_typing)

options: show_submodules: true