Improve handling of builtin symbols in linter rules (#10919)

Add a new method to the semantic model to simplify and improve the correctness of a common pattern
This commit is contained in:
Alex Waygood 2024-04-16 11:37:31 +01:00 committed by GitHub
parent effd5188c9
commit f779babc5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
93 changed files with 886 additions and 588 deletions

View file

@ -5,12 +5,13 @@
pub fn is_standard_library_generic(qualified_name: &[&str]) -> bool {
matches!(
qualified_name,
["", "dict" | "frozenset" | "list" | "set" | "tuple" | "type"]
| [
"collections" | "typing" | "typing_extensions",
"ChainMap" | "Counter"
]
| ["collections" | "typing", "OrderedDict"]
[
"" | "builtins",
"dict" | "frozenset" | "list" | "set" | "tuple" | "type"
] | [
"collections" | "typing" | "typing_extensions",
"ChainMap" | "Counter"
] | ["collections" | "typing", "OrderedDict"]
| ["collections", "defaultdict" | "deque"]
| [
"collections",
@ -247,7 +248,7 @@ pub fn is_immutable_non_generic_type(qualified_name: &[&str]) -> bool {
pub fn is_immutable_generic_type(qualified_name: &[&str]) -> bool {
matches!(
qualified_name,
["", "tuple"]
["" | "builtins", "tuple"]
| [
"collections",
"abc",
@ -285,7 +286,7 @@ pub fn is_immutable_generic_type(qualified_name: &[&str]) -> bool {
pub fn is_mutable_return_type(qualified_name: &[&str]) -> bool {
matches!(
qualified_name,
["", "dict" | "list" | "set"]
["" | "builtins", "dict" | "list" | "set"]
| [
"collections",
"Counter" | "OrderedDict" | "defaultdict" | "deque"