types
Attributes¶
TypeAnnotation
module-attribute
¶
A function parameter's type annotation may be any of the following:
1) type, when declaring any of the built-in Python types
2) typing._GenericAlias, when declaring generic collection types or union types using pre-PEP
585 and pre-PEP 604 syntax (e.g. List[int], Optional[int], or Union[int, None])
3) types.UnionType, when declaring union types using PEP604 syntax (e.g. int | None)
4) types.GenericAlias, when declaring generic collection types using PEP 585 syntax (e.g.
list[int])
types.GenericAlias is a subclass of type, but typing._GenericAlias and types.UnionType are
not and must be considered explicitly.
Functions¶
is_constructible_from_str ¶
Returns true if the provided type can be constructed from a string
Source code in fgpyo/util/types.py
is_list_like ¶
make_enum_parser ¶
make_literal_parser ¶
make_literal_parser(literal: Type[LiteralType], parsers: Iterable[Callable[[str], LiteralType]]) -> partial
Generates a parser function for a literal type object and a set of parsers for the possible parsers to that literal type object
Source code in fgpyo/util/types.py
make_union_parser ¶
Generates a parser function for a union type object and set of parsers for the possible parsers to that union type object
Source code in fgpyo/util/types.py
none_parser ¶
Returns None if the value is 'None', else raises an error
parse_bool ¶
Parses strings into bools accounting for the many different text representations of bools that can be used