refs
¶
Utilities for working with typing.ForwardRef.
This module allows the developer to create and evaluate typing.ForwardRef instances
with additional logic to support forwards compatibility.
Typical Usage
>>> from typelib.py import refs
>>> ref = refs.forwardref("str")
>>> cls = refs.evaluate(ref)
>>> cls is str
True
Functions:
-
forwardref–Create a
typing.ForwardRefinstance from arefstring.
forwardref
¶
forwardref(ref: str | type, *, is_argument: bool = False, module: Any | None = None, is_class: bool = True) -> ForwardRef
Create a typing.ForwardRef instance from a ref string.
This wrapper function will attempt to determine the module name ahead of instantiation if not provided. This is important when resolving the reference to an actual type.
Parameters:
-
(ref¶str | type) –The type reference string.
-
(is_argument¶bool, default:False) –Whether the reference string was an argument to a function (default False).
-
(module¶Any | None, default:None) –The python module in which the reference string is defined (optional)
-
(is_class¶bool, default:True) –Whether the reference string is a class (default True).