mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:41:23 +00:00
Avoid underflow in get_model
matching (#8965)
Closes https://github.com/astral-sh/ruff/issues/8962.
This commit is contained in:
parent
35082b28cd
commit
22d8a989d4
3 changed files with 24 additions and 1 deletions
|
@ -52,3 +52,6 @@ def model_assign() -> None:
|
|||
|
||||
Bad = import_string("django.core.exceptions.ValidationError") # N806
|
||||
ValidationError = import_string("django.core.exceptions.ValidationError") # OK
|
||||
|
||||
Bad = apps.get_model() # N806
|
||||
Bad = apps.get_model(model_name="Stream") # N806
|
||||
|
|
|
@ -101,11 +101,15 @@ pub(super) fn is_django_model_import(name: &str, stmt: &Stmt, semantic: &Semanti
|
|||
return false;
|
||||
};
|
||||
|
||||
if arguments.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Match against, e.g., `apps.get_model("zerver", "Attachment")`.
|
||||
if let Some(call_path) = collect_call_path(func.as_ref()) {
|
||||
if matches!(call_path.as_slice(), [.., "get_model"]) {
|
||||
if let Some(argument) =
|
||||
arguments.find_argument("model_name", arguments.args.len() - 1)
|
||||
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;
|
||||
|
|
|
@ -38,4 +38,20 @@ N806.py:53:5: N806 Variable `Bad` in function should be lowercase
|
|||
54 | ValidationError = import_string("django.core.exceptions.ValidationError") # OK
|
||||
|
|
||||
|
||||
N806.py:56:5: N806 Variable `Bad` in function should be lowercase
|
||||
|
|
||||
54 | ValidationError = import_string("django.core.exceptions.ValidationError") # OK
|
||||
55 |
|
||||
56 | Bad = apps.get_model() # N806
|
||||
| ^^^ N806
|
||||
57 | Bad = apps.get_model(model_name="Stream") # N806
|
||||
|
|
||||
|
||||
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
|
||||
|
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue