8000 `type[Self]` raises TypeError in pydantic-core · Issue #10618 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

type[Self] raises TypeError in pydantic-core #10618

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

Closed
1 task done
kc0506 opened this issue Oct 14, 2024 · 0 comments · Fixed by #10621
Closed
1 task done

type[Self] raises TypeError in pydantic-core #10618

kc0506 opened this issue Oct 14, 2024 · 0 comments · Fixed by #10621
Labels
bug V2 Bug related to Pydantic V2 pending Is unconfirmed

Comments

@kc0506
Copy link
Contributor
kc0506 commented Oct 14, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Traceback

Traceback (most recent call last):
  File "C:\Users\kchon\OneDrive\Desktop\pydantic\new.py", line 7, in <module>
    class A(BaseModel):
  File "C:\Users\kchon\OneDrive\Desktop\pydantic\pydantic\_internal\_model_construction.py", line 227, in __new__
    complete_model_class(
  File "C:\Users\kchon\OneDrive\Desktop\pydantic\pydantic\_internal\_model_construction.py", line 679, in complete_model_class
    cls.__pydantic_validator__ = create_schema_validator(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kchon\OneDrive\Desktop\pydantic\pydantic\plugin\_schema_validator.py", line 50, in create_schema_validator
    return SchemaValidator(schema, config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.SchemaError: Error building "model" validator:
  SchemaError: Error building "model-fields" validator:
  SchemaError: Field "self_field":
  SchemaError: Error building "is-subclass" validator:
  TypeError: '_SpecialForm' object cannot be converted to 'PyType'

Example Code

from pydantic import BaseModel

class A(BaseModel):
    self_field: type[Self]

Python, Pydantic & OS Version

pydantic version: 2.10.0a1                                                                                                         
        pydantic-core version: 2.24.0
          pydantic-core build: profile=release pgo=false
                 install path: C:\Users\kchon\OneDrive\Desktop\pydantic\pydantic
               python version: 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)]
                     platform: Windows-11-10.0.22631-SP0
             related packages: mypy-1.1.1 pydantic-extra-types-2.9.0 pydantic-settings-2.5.2 typing_extensions-4.12.2
                       commit: b8ef9034
@kc0506 kc0506 added bug V2 Bug related to Pydantic V2 pending Is unconfirmed labels Oct 14, 2024
@kc0506 kc0506 changed the title type[Self] cause TypeError in pydantic-core type[Self] raises TypeError in pydantic-core Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2 pending Is unconfirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant
0