Skip to content

typing.get_type_hints with TYPE_CHECKING imports is breaking dependency inspection #5

@RB387

Description

@RB387
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    import annotated_types

class Dependency:
    def __init__(self, db: Database, broken_hint: annotated_types.Any = 1):
        self.broken_hint = broken_hint

injected = injector.inject(Dependency)()

raises Exception

NameError: name 'annotated_types' is not defined

magic_di.exceptions.InspectionError: Failed to inspect
See the exception above

Proposed solution:
Add fallback to inspect.signature or obj.__annotations__

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions