Skip to content

Commit f980e4f

Browse files
committed
Added else branches to handle unrecognized operations
1 parent e476168 commit f980e4f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Lib/test/test_traceback.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4017,12 +4017,14 @@ class CaseChangeOverSubstitution:
40174017
(CaseChangeOverSubstitution, "'BLuch'?"),
40184018
]:
40194019
obj = cls()
4020-
4020+
40214021
if operation == "getattr":
40224022
actual = self.get_suggestion(obj, 'bluch')
40234023
elif operation == "delattr":
40244024
actual = self.get_suggestion(lambda: delattr(obj, 'bluch'))
4025-
4025+
else:
4026+
raise ValueError(f"operation '{operation}' not recognized")
4027+
40264028
self.assertIn(suggestion, actual)
40274029

40284030
def test_getattr_suggestions(self):
@@ -4044,6 +4046,8 @@ class A:
40444046
self.assertIn("'bluch'", self.get_suggestion(lambda: delattr(obj, 'blach')))
40454047
self.assertIn("'bluch'", self.get_suggestion(lambda: delattr(obj, '_luch')))
40464048
self.assertIn("'bluch'", self.get_suggestion(lambda: delattr(obj, '_bluch')))
4049+
else:
4050+
raise ValueError(f"operation '{operation}' not recognized")
40474051

40484052
class B:
40494053
_bluch = None
@@ -4062,6 +4066,8 @@ def method(self, name):
40624066
self.assertIn("'_bluch'", self.get_suggestion(lambda: delattr(obj, '_blach')))
40634067
self.assertIn("'_bluch'", self.get_suggestion(lambda: delattr(obj, '_luch')))
40644068
self.assertNotIn("'_bluch'", self.get_suggestion(lambda: delattr(obj, 'bluch')))
4069+
else:
4070+
raise ValueError(f"operation '{operation}' not recognized")
40654071

40664072
def test_getattr_suggestions_underscored(self):
40674073
self.run_underscored_tests("getattr")
@@ -4078,6 +4084,8 @@ class A:
40784084
actual = self.get_suggestion(obj, 'somethingverywrong')
40794085
elif operation == "delattr":
40804086
actual = self.get_suggestion(lambda: delattr(obj, 'somethingverywrong'))
4087+
else:
4088+
raise ValueError(f"operation '{operation}' not recognized")
40814089
self.assertNotIn("blech", actual)
40824090

40834091
def test_getattr_suggestions_do_not_trigger_for_long_attributes(self):
@@ -4097,6 +4105,8 @@ class MyClass:
40974105
actual = self.get_suggestion(MyClass, name)
40984106
elif operation == "delattr":
40994107
actual = self.get_suggestion(lambda: delattr(obj, name))
4108+
else:
4109+
raise ValueError(f"operation '{operation}' not recognized")
41004110
self.assertNotIn("Did you mean", actual)
41014111
self.assertNotIn("'vvv", actual)
41024112
self.assertNotIn("'mom'", actual)
@@ -4123,14 +4133,16 @@ class A:
41234133
actual = self.get_suggestion(obj, 'bluch')
41244134
elif operation == "delattr":
41254135
actual = self.get_suggestion(lambda: delattr(obj, 'bluch'))
4136+
else:
4137+
raise ValueError(f"operation '{operation}' not recognized")
41264138
self.assertNotIn("blech", actual)
41274139

41284140
def test_getattr_suggestions_do_not_trigger_for_big_dicts(self):
41294141
self.run_do_not_trigger_for_big_dicts_tests("getattr")
41304142

41314143
def test_delattr_suggestions_do_not_trigger_for_big_dicts(self):
41324144
self.run_do_not_trigger_for_big_dicts_tests("delattr")
4133-
4145+
41344146
def test_getattr_suggestions_no_args(self):
41354147
class A:
41364148
blech = None

0 commit comments

Comments
 (0)