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

N805 False positive for class Meta(type(base)) #12736

Closed
randolf-scholz opened this issue Aug 7, 2024 · 1 comment · Fixed by #12770
Closed

N805 False positive for class Meta(type(base)) #12736

randolf-scholz opened this issue Aug 7, 2024 · 1 comment · Fixed by #12770
Assignees
Labels
bug Something isn't working

Comments

@randolf-scholz
Copy link
Contributor

from typing import Protocol

class MyMeta(type):
    def __subclasscheck__(cls, other): ...  # ✅

class MyProtocolMeta(type(Protocol)):
    def __subclasscheck__(cls, other): ...  # ❌

https://play.ruff.rs/5573b0e2-fba5-47c1-bc69-a7e780324a86

@randolf-scholz
Copy link
Contributor Author

Problem is with this function, which does not correctly recognizes metaclass in this case:

pub fn is_metaclass(class_def: &ast::StmtClassDef, semantic: &SemanticModel) -> bool {
any_qualified_name(class_def, semantic, &|qualified_name| {
matches!(
qualified_name.segments(),
["" | "builtins", "type"] | ["abc", "ABCMeta"] | ["enum", "EnumMeta" | "EnumType"]
)
})
}

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