Skip to content

Commit 9d0b73d

Browse files
committed
add more test cases
1 parent cae911d commit 9d0b73d

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

mypy/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ def is_ignored_error_code(self, line: int, code: ErrorCode) -> bool:
838838
if line not in ignores:
839839
return False
840840
if not ignores[line]:
841+
# Empty list means that we ignore all errors
841842
return True
842843
return (
843844
code.code in ignores[line]

mypy/semanal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7533,8 +7533,8 @@ def _get_names_in_scope(self) -> set[str]:
75337533
names.update(self.globals.keys())
75347534

75357535
b = self.globals.get("__builtins__", None)
7536-
if b and isinstance(b.node, MypyFile):
7537-
# Only include public builtins (not _private ones)
7536+
if b:
7537+
assert isinstance(b.node, MypyFile)
75387538
for builtin_name in b.node.names.keys():
75397539
if not (len(builtin_name) > 1 and builtin_name[0] == "_" and builtin_name[1] != "_"):
75407540
names.add(builtin_name)

test-data/unit/check-errorcodes.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ def some_function(x: int) -> int:
7373
x = lenn # E: Name "lenn" is not defined; did you mean "len"? [name-defined]
7474
[builtins fixtures/len.pyi]
7575

76+
[case testErrorCodeUndefinedNameSuggestionClassMethod]
77+
class Foo:
78+
class_attr = 10
79+
def method(self) -> None:
80+
x = class_atr # E: Name "class_atr" is not defined [name-defined]
81+
[builtins fixtures/module.pyi]
82+
83+
[case testErrorCodeUndefinedNameSuggestionMultiple]
84+
total_count = 1
85+
total_counts = 2
86+
x = total_countt # E: Name "total_countt" is not defined; did you mean "total_count" or "total_counts"? [name-defined]
87+
[builtins fixtures/module.pyi]
88+
7689
[case testErrorCodeUndefinedNameSuggestionIgnored]
7790
my_variable = 42
7891
x = my_variabel # type: ignore[name-defined]

0 commit comments

Comments
 (0)