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

hangs on imports from pydantic v2 #14627

Closed
DetachHead opened this issue Feb 7, 2023 · 6 comments
Closed

hangs on imports from pydantic v2 #14627

DetachHead opened this issue Feb 7, 2023 · 6 comments
Labels
bug mypy got something wrong

Comments

@DetachHead
Copy link
Contributor

from pydantic import BaseModel

mypy version: 1.0.0
pydantic version: 2.0.0.dev.0 (installed from github pydantic/pydantic@ef3cc49)

when running mypy with -vvv it gets stuck on:

LOG:  Processing SCC singleton (pydantic_core.core_schema) as inherently stale
@DetachHead DetachHead added the bug mypy got something wrong label Feb 7, 2023
@KotlinIsland
Copy link
Contributor

@JelleZijlstra
Copy link
Member

Using the poor man's debugger of running mypy -vvvvv -c 'from pydantic import BaseModel' --show-traceback and Ctrl-C-ing, it seems to get stuck somewhere in is_subtype:

  File "mypy/types.py", line 2330, in accept
  File "mypy/subtypes.py", line 780, in visit_typeddict_type
  File "mypy/subtypes.py", line 233, in is_equivalent
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 335, in _is_subtype
  File "mypy/types.py", line 2673, in accept
  File "mypy/subtypes.py", line 927, in visit_union_type
  File "mypy/subtypes.py", line 388, in _is_subtype
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 335, in _is_subtype
  File "mypy/types.py", line 2673, in accept
  File "mypy/subtypes.py", line 927, in visit_union_type
  File "mypy/subtypes.py", line 388, in _is_subtype
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 300, in _is_subtype
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 300, in _is_subtype
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 335, in _is_subtype
  File "mypy/types.py", line 2330, in accept
  File "mypy/subtypes.py", line 780, in visit_typeddict_type
  File "mypy/subtypes.py", line 233, in is_equivalent
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 335, in _is_subtype
  File "mypy/types.py", line 2673, in accept
  File "mypy/subtypes.py", line 927, in visit_union_type
  File "mypy/subtypes.py", line 388, in _is_subtype
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 300, in _is_subtype
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 335, in _is_subtype
  File "mypy/types.py", line 2330, in accept
  File "mypy/subtypes.py", line 780, in visit_typeddict_type
  File "mypy/subtypes.py", line 240, in is_equivalent
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 335, in _is_subtype
  File "mypy/types.py", line 2673, in accept
  File "mypy/subtypes.py", line 927, in visit_union_type
  File "mypy/subtypes.py", line 388, in _is_subtype
  File "mypy/subtypes.py", line 175, in is_subtype
  File "mypy/subtypes.py", line 300, in _is_subtype
  File "mypy/subtypes.py", line 174, in is_subtype
  File "/Users/jelle/.pyenv/versions/3.11.1/lib/python3.11/contextlib.py", line 284, in helper
    @wraps(func)

It's indeed plausible this has something to do with the huge Union.

@cdce8p
Copy link
Collaborator

cdce8p commented Feb 8, 2023

Could this be a super massive black hole union: https://github.com/pydantic/pydantic-core/blob/bfb373c269ae2bfcc32c15e4f1e59f2cee30b2ac/pydantic_core/core_schema.py#L2547?

Probably. It's also used recursively in some places which doesn't help either.
I added a common base type which seems to resolve this particular issue. pydantic/pydantic-core#387

As for mypy, it seems there is a performance issue with large unions in particular. That might be something to look into.
Had a similar issue a while back but that was with custom Enum types and a large Union type. Resolved it in a similar way though by adding a base class and using that instead. home-assistant-libs/zwave-js-server-python#435

@KotlinIsland
Copy link
Contributor

I had a similar issues here KotlinIsland#399

@cdce8p
Copy link
Collaborator

cdce8p commented Feb 8, 2023

Maybe a first step could be to add a section to the Common issues page. That way users could at least find and know about it.

@samuelcolvin
Copy link
Contributor

This is a duplicate of #14034 I think.

@DetachHead DetachHead closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

5 participants