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

Faulty Pyright error on frozen daughters (frozen=True) of non-frozen parents (frozen=False) #9171

Open
4 of 13 tasks
caniko opened this issue Apr 5, 2024 · 3 comments
Open
4 of 13 tasks

Comments

@caniko
Copy link
Contributor

caniko commented Apr 5, 2024

Initial Checks

  • I have searched Google & GitHub for similar requests and couldn't find anything
  • I have read and followed the docs and still think this feature is missing

Description

Some of my models used in FastAPI come from 3rd party libraries like fastapi-users; here the models are frozen=False. Currently, I can actually freeze them, but pyright errors.

Idea:

class MyModel(BaseModel, frozen=False):
     a: int

class MyDaughter(MyModel, frozen=True):
    b: int

This gives the following pyright error:

error: A frozen class cannot inherit from a class that is not frozen

Affected Components

@caniko caniko changed the title Freeze daughters (frozen=True) of non-frozen parents (frozen=False) Faulty Pyright error on frozen daughters (frozen=True) of non-frozen parents (frozen=False) Apr 5, 2024
@sydney-runkle
Copy link
Member

sydney-runkle commented Apr 9, 2024

@caniko,

What happens with dataclasses? I'm guessing we'd want to mimick that behavior...

@caniko
Copy link
Contributor Author

caniko commented Apr 19, 2024

@sydney-runkle

Pydantic base models can actually inherit from frozen to non-frozen, but the issue is pyright. Pyright treats BaseModel as dataclass in this instance. Dataclass inheritance from frozen to non-frozen is impossible; however, not the case for BaseModel.

@wikiped
Copy link

wikiped commented May 5, 2024

pyright's dev point of view

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

No branches or pull requests

3 participants