egrecho.utils.patch.simple_parse_patch.annotation_utils#

egrecho.utils.patch.simple_parse_patch.annotation_utils.get_field_annotations#

egrecho.utils.patch.simple_parse_patch.annotation_utils.get_field_annotations.evaluate_string_annotation(annotation, containing_class=None)[source]#

Attempts to evaluate the given annotation string, to get a ‘live’ type annotation back.

Any exceptions that are raised when evaluating are raised directly as-is.

NOTE: This is probably not 100% safe. I mean, if the user code puts urls and stuff in their type annotations, and then uses simple-parsing, then sure, that code might get executed. But I don’t think it’s my job to prevent them from shooting themselves in the foot, you know what I mean?

Return type:

type

egrecho.utils.patch.simple_parse_patch.annotation_utils.get_field_annotations.get_field_type_from_annotations(some_class, field_name)[source]#

Get the annotation for the given field, in the ‘old-style’ format with types from typing.List, typing.Union, etc.

If the script uses from __future__ import annotations, and we are in python<3.9, Then we need to actually first make this forward-compatibility ‘patch’ so that we don’t run into a “type object is not subscriptable” error.

NOTE: If you get errors of this kind from the function below, then you might want to add an entry to the forward_refs_to_types dict above.

Return type:

type