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

Incomplete resolving of subclass chains in runtime-evaluated-base-classes #7893

Closed
disrupted opened this issue Oct 10, 2023 · 0 comments · Fixed by #8768
Closed

Incomplete resolving of subclass chains in runtime-evaluated-base-classes #7893

disrupted opened this issue Oct 10, 2023 · 0 comments · Fixed by #8768
Assignees
Labels
bug Something isn't working

Comments

@disrupted
Copy link

Extracted from #7866 (comment)

Ruff doesn't reliably detect the base class (even within the same file).

given this example

from abc import ABC
from pydantic import BaseModel

class Model(BaseModel):
    x: str


class Empty(BaseModel):
    ...


class Abstract(Empty, ABC):
    inner: Model

Ruff evaluates the following classes and their bases (I simply placed some log statements in this function)

class_def.bases().iter().any(|base| {

class Model  bases: [Some(["pydantic", "BaseModel"])]
class Abstract  bases: [None, Some(["abc", "ABC"])]

notice the absence of Empty and how Abstract then doesn't get detected as BaseModel.

Therefore, flake8-type-checking rules often result in false positives as it's unable to correctly resolve the base class.

@charliermarsh charliermarsh added the bug Something isn't working label Oct 10, 2023
@charliermarsh charliermarsh self-assigned this Nov 16, 2023
charliermarsh added a commit that referenced this issue Nov 19, 2023
If you define a subclass of `pydantic.BaseModel`, and then a subclass of
_that_ class in the same file, we'll now correctly treat it as
runtime-evaluated.

Closes #7893.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants