Skip to content

Inject[] does not let the interface show up. #158

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

Open
mozesa opened this issue Oct 8, 2020 · 8 comments
Open

Inject[] does not let the interface show up. #158

mozesa opened this issue Oct 8, 2020 · 8 comments

Comments

@mozesa
Copy link

mozesa commented Oct 8, 2020

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!

@jstasiak
Copy link
Collaborator

jstasiak commented Oct 8, 2020

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.

@mozesa
Copy link
Author

mozesa commented Oct 8, 2020

Hello @jstasiak,

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

I keep open this issue and later will update.

@jstasiak
Copy link
Collaborator

jstasiak commented Oct 8, 2020

Sure thing!

@mozesa
Copy link
Author

mozesa commented Oct 12, 2020

issue created.

@JosXa
Copy link

JosXa commented Dec 8, 2020

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.

@halbow
Copy link

halbow commented Feb 27, 2025

Hi,

I'm still having this issue with Pycharm (mypy works fine) with the Annotation Alias Inject[Something].
A workaround for me was to use Annotated[Something, _inject_marker] (using the Annotated keyword directly instead of the annotation aliasInject).

@jstasiak as it seems Pycharm will not fix this issue soon, would you consider making _inject_marker public ? That would allow to have a proper workaround for tools not supporting the alias from PEP-0593 yet

@davidparsson
Copy link
Collaborator

would you consider making _inject_marker public ?

I think that is a reasonable request, allowing a workaround for those that think it's worth it. We should make the _noinject_marker public at the same time, and ideally update the documentation.

davidparsson added a commit that referenced this issue Mar 8, 2025
This is probably as close as a fix for #158 as we'll get on this end.
@davidparsson
Copy link
Collaborator

I have opened a PR for this in #269.

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

No branches or pull requests

5 participants