Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -5086,6 +5086,32 @@ def baz(self):
self.assertNotIn('self.', suggestion)
self.assertIn("'spam'", suggestion)

def test_name_error_with_getattr(self):
class A:
def __getattr__(self, x):
print(x)
print(qq)
class B:
def __getattribute__(self, x):
print(x)
print(qq)
Comment on lines +5091 to +5097

for instance in (A(), B()):
with self.subTest(instance=instance):
actual = self.get_suggestion(instance, "pop")
self.assertIn("name 'qq' is not defined", actual)
self.assertEqual(actual.count("NameError"), 1)

def test_name_error_with_property_name(self):
class A:
@property
def past(self):
past
instance = A()
actual = self.get_suggestion(instance, "past")
self.assertIn("name 'past' is not defined", actual)
self.assertEqual(actual.count("NameError"), 1)

def test_unbound_local_error_does_not_match(self):
def func():
something = 3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix pyrepl crash when a :exc:`NameError` occurs in the :meth:`~object.__getattr__`, :meth:`~object.__getattribute__` and any method of a class.
Loading