mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-99139: Improve NameError error suggestion for instances (#99140)
This commit is contained in:
parent
a0bc75e2fd
commit
99e2e60cb2
7 changed files with 92 additions and 0 deletions
|
@ -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():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue