ivankorobkov / python-inject

Python dependency injection
Apache License 2.0
694 stars 79 forks source link

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

Closed juancerezo closed 6 months ago

juancerezo commented 6 months ago

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 commented 6 months ago

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

juancerezo commented 6 months ago

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