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

Exposing Mypy-compatible type information #966

Closed
ktosiek opened this issue May 12, 2019 · 8 comments
Closed

Exposing Mypy-compatible type information #966

ktosiek opened this issue May 12, 2019 · 8 comments
Labels

Comments

@ktosiek
Copy link

ktosiek commented May 12, 2019

I'd like to use Mypy for checking a Graphene-based app. Is anyone working on stubs, or even better - a Mypy plugin?

What I imagine is writing:

class Me(ObjectType[User]):
    full_name = graphene.String()
    def resolve_full_name(self, info):
        return self.get_full_name()

And getting a guarantee that User.get_full_name() returns something assignable to Optional[String].

@ktosiek
Copy link
Author

ktosiek commented May 12, 2019

Looks like this might not be possible - Plugin.get_function_hook can override the type of full_name, and Plugin.get_subclass_hook can look at types of actual methods, but I haven't found a way to make those two communicate.

An approach closer to #729 (comment) seems to make more sense - this way everything to know about a resolver lives in one place.

@dvndrsn
Copy link
Contributor

dvndrsn commented May 15, 2019

From my understanding, much (if not all) of the Graphene and graphql-core codebase is type hinted with Python 2.7 style annotations, but all of the user generated types have attributes through some metaprogramming, which can be a challenge to generate stubs for. There's a mypy issue here discussing a similar topic:

python/mypy#1310

@ktosiek
Copy link
Author

ktosiek commented May 15, 2019

Those type hints are not exported, see this PEP-561 section. And as you've noted, they don't cover that much of user's code.

For the metaprogramming part a plugin would be needed. I've looked into it, but I'm not sure how to tie field declarations with types of resolvers (maybe we'll need a new mypy hook?).

@stale
Copy link

stale bot commented Jul 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 29, 2019
@stale stale bot closed this as completed Aug 5, 2019
@ckarnell
Copy link

ckarnell commented Jan 8, 2020

Hi all, I created a repo for stubs for this library and wrote a plugin for it to match resolver function definitions to their corresponding Field attributes. Feel free to use / file issues / contribute!

https://github.com/trialspark/graphene-stubs

@PureTryOut
Copy link

That packages hasn't seen an update since March 2020, only 2 months after it was announced here. It would be great if mypy itself can export type hints, can this issue be re-opened?

@ryanovas
Copy link

ryanovas commented Sep 4, 2023

Would also like to see this re-opened

@tekhenu
Copy link

tekhenu commented Oct 16, 2023

Bump. This is still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants