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

AssertionError: Internal error: unresolved placeholder type #16809

Closed
janbjorge opened this issue Jan 23, 2024 · 4 comments
Closed

AssertionError: Internal error: unresolved placeholder type #16809

janbjorge opened this issue Jan 23, 2024 · 4 comments
Labels

Comments

@janbjorge
Copy link

Crash Report

I have a pydantic v2 model. Given as, this seems to blow up mypy, it was working in the begining. But when i moved some files around it stopped. As you can see from the code below everything is locally defined for this class.

from __future__ import annotations

from typing import Dict, Union

from pydantic import RootModel


class Parameters(RootModel[Dict[str, Union[int, float, str, "Parameters"]]]):
    ...

Traceback

 mypy . --show-traceback
./src/fmu/dataio/models/parameters.py:10: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.8.0
Traceback (most recent call last):
  File "mypy/semanal.py", line 6539, in accept
  File "mypy/nodes.py", line 1142, in accept
  File "mypy/semanal.py", line 1612, in visit_class_def
  File "mypy/semanal.py", line 1697, in analyze_class
  File "mypy/semanal.py", line 1731, in analyze_class_body_common
  File "mypy/semanal.py", line 1816, in apply_class_plugin_hooks
  File "/Users/JLOV/.pyenv/versions/3.10.13/envs/dataio/lib/python3.10/site-packages/pydantic/mypy.py", line 183, in _pydantic_model_class_maker_callback
    return transformer.transform()
  File "/Users/JLOV/.pyenv/versions/3.10.13/envs/dataio/lib/python3.10/site-packages/pydantic/mypy.py", line 453, in transform
    'fields': {field.name: field.serialize() for field in fields},
  File "/Users/JLOV/.pyenv/versions/3.10.13/envs/dataio/lib/python3.10/site-packages/pydantic/mypy.py", line 453, in <dictcomp>
    'fields': {field.name: field.serialize() for field in fields},
  File "/Users/JLOV/.pyenv/versions/3.10.13/envs/dataio/lib/python3.10/site-packages/pydantic/mypy.py", line 378, in serialize
    'type': self.type.serialize(),
  File "mypy/types.py", line 1459, in serialize
  File "mypy/types.py", line 2868, in serialize
  File "mypy/types.py", line 3051, in serialize
AssertionError: Internal error: unresolved placeholder type fmu.dataio.models.parameters.Parameters
./src/fmu/dataio/models/parameters.py:10: : note: use --pdb to drop into pdb

To Reproduce

(Write what you did to reproduce the crash. Full source code is
appreciated. We also very much appreciate it if you try to narrow the
source down to a small stand-alone example.)

Your Environment

  • Mypy version used: 1.8.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): See below.
  • Python version used: 3.10.13
  • Operating system and version: Darwin AC-W6JD2YH37N 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020 arm64

mypy.ini:

[mypy]
plugins = pydantic.mypy
disallow_untyped_defs = True
exclude = ^((tests|docs|examples|build)/|conftest.py?)
extra_checks = True
ignore_missing_imports = True
python_version = 3.8
strict_equality = True
warn_redundant_casts = True
warn_unused_configs = True
warn_unused_ignores = True
@mikeedjones
Copy link

mikeedjones commented Jan 31, 2024

also seeing this same error with 1.8.0 on openai SDK v1.11.0 and 3.11.3-slim-bullseye image

/usr/local/lib/python3.11/site-packages/openai/_models.py:408: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.8.0
/usr/local/lib/python3.11/site-packages/openai/_models.py:408: : note: use --pdb to drop into pdb
Traceback (most recent call last):
  File "mypy/semanal.py", line 6539, in accept
  File "mypy/nodes.py", line 1142, in accept
  File "mypy/semanal.py", line 1612, in visit_class_def
  File "mypy/semanal.py", line 1697, in analyze_class
  File "mypy/semanal.py", line 1731, in analyze_class_body_common
  File "mypy/semanal.py", line 1816, in apply_class_plugin_hooks
  File "/usr/local/lib/python3.11/site-packages/pydantic/mypy.py", line 187, in _pydantic_model_class_maker_callback
    return transformer.transform()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pydantic/mypy.py", line 478, in transform
    self.add_initializer(fields, config, is_settings, is_root_model)
  File "/usr/local/lib/python3.11/site-packages/pydantic/mypy.py", line 856, in add_initializer
    args = self.get_field_arguments(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pydantic/mypy.py", line 1038, in get_field_arguments
    arguments = [
                ^
  File "/usr/local/lib/python3.11/site-packages/pydantic/mypy.py", line 1039, in <listcomp>
    field.to_argument(
  File "/usr/local/lib/python3.11/site-packages/pydantic/mypy.py", line 346, in to_argument
    variable=self.to_var(current_info, use_alias),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pydantic/mypy.py", line 373, in to_var
    return Var(name, self.expand_type(current_info))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pydantic/mypy.py", line 362, in expand_type
    raise _DeferAnalysis()
_DeferAnalysis: 

@frankie567
Copy link

I don't think it's a problem with mypy but rather with the Pydantic plugin: the bug was fixed on their side and will soon be released:

@janbjorge
Copy link
Author

That looks be correct(remove the pydantic plugin in my .ini file and it runnes), it would however been epic if the trackback give some indication that it was a plugin that failed.

@frankie567
Copy link

It does, actually:

  File "/usr/local/lib/python3.11/site-packages/pydantic/mypy.py", line 362, in expand_type
    raise _DeferAnalysis()
_DeferAnalysis: 

@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2024
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

4 participants