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

Fix change overload order to allow correct type hinting (Mistaken PR) #98

Closed
wants to merge 1 commit into from
Closed

Fix change overload order to allow correct type hinting (Mistaken PR) #98

wants to merge 1 commit into from

Conversation

juancerezo
Copy link

@juancerezo juancerezo commented Mar 29, 2024

Hi Ivan,

To fix the issue Type hint broken for inject.attr when using ABCMeta just change the order of typing overloads. From more specific to more abstract.

Hasheable type can match with Type[T]. To prevent that, just declare first Hasheable overload and Type[T] later:

I have change this (in all @overload declarations):

@overload
def attr(cls: Type[T]) -> T: ...

@overload
def attr(cls: Hashable) -> Injectable: ...

To this:

@overload
def attr(cls: Hashable) -> Injectable: ...

@overload
def attr(cls: Type[T]) -> T: ...

Cheers! :)

@juancerezo juancerezo marked this pull request as ready for review March 29, 2024 22:20
@juancerezo juancerezo closed this Mar 29, 2024
@juancerezo
Copy link
Author

Sorry, this is a mistake with my code annotations... ^^' I'm continue investigating... :/

@juancerezo juancerezo deleted the fix/abcmeta-broken-type branch March 29, 2024 22:50
@juancerezo
Copy link
Author

It seems that version 5.2.1 and python 3.12 solve the issues with type hinting... :/

@juancerezo juancerezo changed the title Fix ivankorobkov/python-inject#69 change overload order to allow correct type hinting Fix change overload order to allow correct type hinting (Mistaken PR) Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant