Skip to content

Latest commit

 

History

History
29 lines (19 loc) · 1.48 KB

File metadata and controls

29 lines (19 loc) · 1.48 KB
https://img.shields.io/github/actions/workflow/status/InvestmentSystems/typing-resolver/test.yml?branch=default&label=test&logo=Github

Overview

typing-resolver provides a more helpful alternative to typing.get_type_hints() by resolving type annotations using a reconstructed import namespace. It is intended for codebases that rely on TYPE_CHECKING imports, conditional imports, or inherited annotations that might not be present at runtime.

Problem

typing.get_type_hints() evaluates annotations in a limited namespace. If an annotation references a name that is not imported at runtime (for example, under if TYPE_CHECKING:), resolution fails with NameError.

Solution

This package rebuilds a local namespace by collecting ALL import statements from inside ALL module(s) in an type object's MRO and uses that namespace when resolving type hints.