injector icon indicating copy to clipboard operation
injector copied to clipboard

Inject[] does not let the interface show up.

Open mozesa opened this issue 5 years ago • 8 comments
trafficstars

Hello @alecthomas,

first of all let me to say Thank you! for this outstanding package.

I try to utilize the feature of PEP 593 which actually works fine, but let speak the pictures. image image

As you can see, when I use Inject[], the PyCharm doesn't show the interface's methods.

But it works when I use the Annotated[interface: Type[T], ...]. image

Thanks for your help in advance!

mozesa avatar Oct 08 '20 08:10 mozesa

Hey @mozesa. I'll answer in @alecthomas's stead as I maintain this project right now – I think you need to take this up with the PyCharm folks, I don't use it and I'm afraid I can't help much here, everything seems good on our side.

jstasiak avatar Oct 08 '20 18:10 jstasiak

Hello @jstasiak,

Thanks for your reply. I will create a ticket on PyCharm's side.

I keep open this issue and later will update.

mozesa avatar Oct 08 '20 18:10 mozesa

Sure thing!

jstasiak avatar Oct 08 '20 19:10 jstasiak

issue created.

mozesa avatar Oct 12 '20 07:10 mozesa

Yes, the JetBrains folks unfortunately lag very much behind updating their type checker. I could go on another rant, but I'll be civil and leave it at that.

The problem is that the Annotated feature has not been created with "regular" __class_getitem__ classmethods, but instead another one of these _SpecialForms. I just spent 30 minutes trying to come up with a workaround, but I couldn't come up with anything better than def PyCharmCompatibleInject(typ: T) -> T: ... which could somehow patch that missing behavior, but it looks ugly as hell: def foo(bar: PChInject(Bar)). meh.

JosXa avatar Dec 08 '20 00:12 JosXa