mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
[3.13] gh-132385: Fix instance error suggestions trigger potential exceptions in traceback
(GH-132387) (#133297)
gh-132385: Fix instance error suggestions trigger potential exceptions in `traceback` (GH-132387)
(cherry picked from commit 641253cfac
)
Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
parent
6a919d0488
commit
16e9e74a8b
3 changed files with 29 additions and 1 deletions
|
@ -4549,6 +4549,28 @@ class SuggestionFormattingTestBase:
|
|||
actual = self.get_suggestion(instance.foo)
|
||||
self.assertNotIn("self.blech", actual)
|
||||
|
||||
def test_unbound_local_error_with_side_effect(self):
|
||||
# gh-132385
|
||||
class A:
|
||||
def __getattr__(self, key):
|
||||
if key == 'foo':
|
||||
raise AttributeError('foo')
|
||||
if key == 'spam':
|
||||
raise ValueError('spam')
|
||||
|
||||
def bar(self):
|
||||
foo
|
||||
def baz(self):
|
||||
spam
|
||||
|
||||
suggestion = self.get_suggestion(A().bar)
|
||||
self.assertNotIn('self.', suggestion)
|
||||
self.assertIn("'foo'", suggestion)
|
||||
|
||||
suggestion = self.get_suggestion(A().baz)
|
||||
self.assertNotIn('self.', suggestion)
|
||||
self.assertIn("'spam'", suggestion)
|
||||
|
||||
def test_unbound_local_error_does_not_match(self):
|
||||
def func():
|
||||
something = 3
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue