inspect_annotations | My Python Project

# inspect_annotations module

Annotation parsing. For links inside annotations see test_inspect.TypeLinks.

## Classes

class AContainer
  A generic class. No parent class info extracted yet.
class AContainer2
  Another class derived from a typing thing.
class Foo
  A class with properties
class FooSlots
  A class with slots

## Functions

def annotated_positional_keyword(bar = False, *, foo: str, **kwargs)
  Function with explicitly delimited keyword args and type annotations
def annotation(param: typing.List[int], another: bool, third: str = 'hello') -> float
  An annotated function
def annotation_any(a: typing.Any)
  Annotation with the Any type
def annotation_callable(a: typing.Callable[[float, int], str])
  Annotation with the Callable type
def annotation_callable_no_args(a: typing.Callable[[], typing.Dict[int, float]])
  Annotation with the Callable type w/o arguments
def annotation_ellipsis(a: typing.Callable[[...], int], b: typing.Tuple[str, ...])
  Annotation with ellipsis
def annotation_func_instead_of_type(a)
  Annotation with a function instead of a type, ignored
def annotation_func_instead_of_type_nested(a, b, c)
  Annotations with nested problems, ignoring the whole thing
def annotation_generic(a: typing.List[Tp]) -> Tp
  Annotation with a generic type
def annotation_list_noparam(a: typing.List)
  Annotation with the unparametrized List type. 3.7 and 3.8 adds an implicit TypeVar to it, 3.6, 3.9 and 3.10 not, so the output is different between the versions.
def annotation_optional(a: typing.Optional[float])
  Annotation with the Optional type
def annotation_strings(param: typing.List[int], another: bool, third: str = 'hello') -> float
  Annotated using strings, should result in exactly the same as annotation()
def annotation_tuple_instead_of_tuple(a)
  Annotation with a tuple instead of Tuple, ignored
def annotation_union(a: typing.Union[float, int])
  Annotation with the Union type
def annotation_union_of_undefined(a: typing.Union[int, something.Undefined])
  Annotation with an union that has an undefined type inside, where we can't use isinstance either
def annotation_union_second_bracketed(a: typing.Union[float, typing.List[int]])
  Annotation with the Union type and second type bracketed, where we can't use isinstance
def args_kwargs(a, b, *args, **kwargs)
  Function with args and kwargs
def no_annotation(a, b, z)
  Non-annotated function
def no_annotation_default_param(param, another, third = 'hello')
  Non-annotated function with a default parameter
def partial_annotation(foo, param: typing.Tuple[int, int], unannotated, cls: object)
  Partially annotated function
def positional_keyword(positional_kw, *, kw_only)
  Function with explicitly delimited keyword args
def returns_none(a: typing.Callable[[], None]) -> None
  In order to disambiguate between a missing return annotation and an annotated none, the None return annotation is kept, converted from NoneType to None
def returns_none_type(a: typing.Callable[[], None]) -> None
  And it should behave the same when using None or type(None)

## Data

ANNOTATED_VAR: typing.Tuple[bool, str] = (False, 'No.')
UNANNOTATED_VAR = 3.45