mirror of https://github.com/astral-sh/ruff
Allow class names when `apps.get_model` is a non-string (#9065)
See: https://github.com/astral-sh/ruff/issues/7675#issuecomment-1848206022
This commit is contained in:
parent
b7dd2b5941
commit
20e33bf514
|
|
@ -55,3 +55,6 @@ def model_assign() -> None:
|
|||
|
||||
Bad = apps.get_model() # N806
|
||||
Bad = apps.get_model(model_name="Stream") # N806
|
||||
|
||||
Address: Type = apps.get_model("zerver", variable) # OK
|
||||
ValidationError = import_string(variable) # N806
|
||||
|
|
|
|||
|
|
@ -112,7 +112,11 @@ pub(super) fn is_django_model_import(name: &str, stmt: &Stmt, semantic: &Semanti
|
|||
arguments.find_argument("model_name", arguments.args.len().saturating_sub(1))
|
||||
{
|
||||
if let Some(string_literal) = argument.as_string_literal_expr() {
|
||||
return string_literal.value.to_str() == name;
|
||||
if string_literal.value.to_str() == name {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -127,7 +131,9 @@ pub(super) fn is_django_model_import(name: &str, stmt: &Stmt, semantic: &Semanti
|
|||
if let Some(argument) = arguments.find_argument("dotted_path", 0) {
|
||||
if let Some(string_literal) = argument.as_string_literal_expr() {
|
||||
if let Some((.., model)) = string_literal.value.to_str().rsplit_once('.') {
|
||||
return model == name;
|
||||
if model == name {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,15 @@ N806.py:57:5: N806 Variable `Bad` in function should be lowercase
|
|||
56 | Bad = apps.get_model() # N806
|
||||
57 | Bad = apps.get_model(model_name="Stream") # N806
|
||||
| ^^^ N806
|
||||
58 |
|
||||
59 | Address: Type = apps.get_model("zerver", variable) # OK
|
||||
|
|
||||
|
||||
N806.py:60:5: N806 Variable `ValidationError` in function should be lowercase
|
||||
|
|
||||
59 | Address: Type = apps.get_model("zerver", variable) # OK
|
||||
60 | ValidationError = import_string(variable) # N806
|
||||
| ^^^^^^^^^^^^^^^ N806
|
||||
|
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue