gh-99139: Improve NameError error suggestion for instances (#99140)

This commit is contained in:
Pablo Galindo Salgado 2022-11-06 13:52:06 +00:00 committed by GitHub
parent a0bc75e2fd
commit 99e2e60cb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 92 additions and 0 deletions

View file

@ -3356,6 +3356,31 @@ class SuggestionFormattingTestBase:
actual = self.get_suggestion(func)
self.assertNotIn("blech", actual)
def test_name_error_with_instance(self):
class A:
def __init__(self):
self.blech = None
def foo(self):
blich = 1
x = blech
instance = A()
actual = self.get_suggestion(instance.foo)
self.assertIn("self.blech", actual)
def test_unbound_local_error_with_instance(self):
class A:
def __init__(self):
self.blech = None
def foo(self):
blich = 1
x = blech
blech = 1
instance = A()
actual = self.get_suggestion(instance.foo)
self.assertNotIn("self.blech", actual)
def test_unbound_local_error_does_not_match(self):
def func():