Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RB387 opened this issue Mar 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@RB387
Copy link
Collaborator

RB387 commented Mar 28, 2024

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__

@RB387 RB387 added the bug Something isn't working label Mar 28, 2024
@RB387 RB387 changed the title typing.get_type_hints with TYPE_CHECKING imports are breaking dependency inspection typing.get_type_hints with TYPE_CHECKING imports is breaking dependency inspection Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant