bpo-38530: Match exactly AttributeError and NameError when offering suggestions (GH-25443)

This commit is contained in:
Pablo Galindo 2021-04-16 17:12:03 +01:00 committed by GitHub
parent 3b82cae774
commit 0ad81d4db2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -1537,6 +1537,21 @@ class NameErrorTests(unittest.TestCase):
self.assertNotIn("blech", err.getvalue())
def test_unbound_local_error_doesn_not_match(self):
def foo():
something = 3
print(somethong)
somethong = 3
try:
foo()
except UnboundLocalError as exc:
with support.captured_stderr() as err:
sys.__excepthook__(*sys.exc_info())
self.assertNotIn("something", err.getvalue())
class AttributeErrorTests(unittest.TestCase):
def test_attributes(self):
# Setting 'attr' should not be a problem.