{"record":{"id":"58d5a4d535321d69","repo":"astral-sh/ruff","slug":"expected-scopekind-function-scopekind-lambda","errorCode":null,"errorMessage":"Expected ScopeKind::Function | ScopeKind::Lambda","messagePattern":"Expected ScopeKind::Function \\| ScopeKind::Lambda","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs","lineNumber":530,"sourceCode":"                        && !visibility::is_abstract(decorator_list, checker.semantic())\n                        && !visibility::is_override(decorator_list, checker.semantic())\n                        && !visibility::is_overload(decorator_list, checker.semantic())\n                    {\n                        // we use `method()` here rather than `function()`, as although `__new__` is\n                        // an implicit staticmethod, `__new__` methods must always have at least one parameter\n                        method(Argumentable::StaticMethod, parameters, scope, checker);\n                    }\n                }\n            }\n        }\n        ScopeKind::Lambda(ast::ExprLambda { parameters, .. }) => {\n            if let Some(parameters) = parameters {\n                if checker.is_rule_enabled(Argumentable::Lambda.rule_code()) {\n                    function(Argumentable::Lambda, parameters, scope, checker);\n                }\n            }\n        }\n        _ => panic!(\"Expected ScopeKind::Function | ScopeKind::Lambda\"),\n    }\n}\n","sourceCodeStart":512,"sourceCodeEnd":533,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/flake8_unused_arguments/rules/unused_arguments.rs#L512-L533","documentation":"Internal panic in Ruff's flake8-unused-arguments implementation (ARG rules). `unused_arguments` dispatches on `scope.kind` and handles `Function` and `Lambda` scopes, treating any other scope kind as unreachable because the checker only invokes the rule for those two scope types. Hitting it signals a violated internal invariant — a Ruff bug, not a user error.","triggerScenarios":"Linting code where the unused-arguments check is entered from a scope whose `kind` is neither a function nor a lambda (e.g. module/class scope). Only reachable through a Ruff regression, a custom plugin registering the visitor on the wrong scope, or desynced scope stack after parser/semantic-model changes.","commonSituations":"Running `ruff check --select ARG` on a codebase after a Ruff upgrade that changed scope construction; forks or API consumers of the linter crates that call `unused_arguments` directly with an incorrect scope; exotic syntax triggering a scope-classification bug.","solutions":["Pin or upgrade Ruff to a release where the ARG scope dispatch bug is fixed; search the repo issues for 'Expected ScopeKind::Function | ScopeKind::Lambda'","Reproduce with `ruff check --isolated --select ARG <file>` and minimize the file, then report the snippet upstream","Exclude ARG rules from the run (`ignore = [\"ARG\"]` in `lint`) until fixed","If you call `unused_arguments` from the ruff_linter API, guard your caller to only pass `ScopeKind::Function` or `ScopeKind::Lambda` scopes"],"exampleFix":"# before\nruff check --select ARG001,ARG002,ARG005 .\n\n# after (suppress the crashing rule family until the regression is fixed)\n[tool.ruff.lint]\nignore = [\"ARG\"]","handlingStrategy":"validation","validationCode":"// Rust caller-side guard before invoking the rule\nif !matches!(scope.kind, ScopeKind::Function(_) | ScopeKind::Lambda(_)) {\n    return; // skip instead of reaching the panic arm\n}","typeGuard":"fn is_fn_or_lambda_scope(scope: &Scope) -> bool {\n    matches!(scope.kind, ScopeKind::Function(_) | ScopeKind::Lambda(_))\n}","tryCatchPattern":null,"preventionTips":["Only schedule ARG rules for function/lambda scopes in the checker traversal","Pin Ruff versions in CI and upgrade after checking the changelog","Minimize and report any ARG panic to the Ruff issue tracker","As a codebase user: keep `lint.ignore` ready to drop `ARG` temporarily if a release crashes"],"tags":["rust","panic","ruff","unused-arguments","internal-invariant"],"backgroundTag":"linter-internal-panic","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}