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: |
generate_namespace_typing |
Generates a typed namespace class for a given argparser. |
dump_struct_signature
#
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 |
---|---|---|---|
|
ArgumentParser
|
the argparser whose namespace is to be produced |
required |
|
str
|
name of newly created namespace |
required |
|
Iterable[tuple[type[Any], str]] | None
|
aliases Action.type to one type to an arbitrary string representation |
None
|
|
Iterable[tuple[Any, str]] | None
|
aliases a Action.default value to an arbitrary string representation |
None
|
|
str | None
|
description of namespace In Numpydoc style, this corresponds to the
|
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