question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PyCharm warning: Expected type 'ObjectType', got 'Type[Query]' instead

See original GitHub issue

class Query(graphene.ObjectType):
    # ...

schema = Schema(query=Query)

image

Related to #814 which was automatically closed due to staleness.

Any ideas?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:15
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
formigonecommented, Apr 30, 2020

Came across this looking for the same PyCharm warning, but in a different situation. I’m not a user of this repo, so I won’t take the time to locate the code and PR the simple fix for it.

TL/DR:

Whenever you see PyCharm complain with

Expected type X, got Type[X] instead

that’s a possible type hinting misunderstanding. See this for more information.

In summary:

# Wrong
class Schema:
   def __init__(self, query: MyClass):

# Right
from typing import Type

class Schema:
   def __init__(self, query: Type[MyClass]):
3reactions
Abhi904485commented, Sep 7, 2020

Thank you for the reply! I’m sorry I still don’t understand how to do this, since I’m not defining the class Schema in my own code. All I’m doing is using graphene.Schema: image So I don’t know where the type hint should go, since there’s no class Schema in my code… Would you be so kind to tell me how you accomplished this? Did you subclass graphene.Schema? Thanks in advance 😃

change the doc present in graphene/types/schema.py

replace:

query (ObjectType): Root query ObjectType. Describes entry point for fields to read data in your Schema.

with

query (Type[ObjectType]): Root query ObjectType. Describes entry point for fields to read data in your Schema.

After that problem will resolve

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deal with PyCharm's "Expected type X, got Y instead"
Expand the Python tab. Scroll down to Type Checker and uncheck it. PyCharm should now stop issuing warnings about incorrect function arguments.
Read more >
Expected type 'ObjectType', got 'Type[Query]' instead
PyCharm warning : Expected type 'ObjectType', got 'Type[Query]' instead.
Read more >
False Positive: Expected type 'type', got 'object' instead for ...
Run PyCharm and create a new python project with python 3.8 ... PyCharm reports warning Expected type 'type', got 'object' instead for TypeVar...
Read more >
Expected type 'object', got 'str' instead - JetBrains YouTrack
After the latest upgrade, I have started to get a lot of warnings saying Expected type 'object', got 'str' instead. I don't know...
Read more >
Possible type checking bug: Expected type 'Model', got 'Type ...
... type 'Model', got 'Type[Model]' instead. The following code produces wrong type warnings (also happens with other classes). PyCharm installed via snap.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found