Skip to content

Commit 57deaf3

Browse files
committed
Added else branches to handle unrecognized operations
1 parent 04254ad commit 57deaf3

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
@@ -4075,12 +4075,14 @@ class CaseChangeOverSubstitution:
40754075
(CaseChangeOverSubstitution, "'BLuch'?"),
40764076
]:
40774077
obj = cls()
4078-
4078+
40794079
if operation == "getattr":
40804080
actual = self.get_suggestion(obj, 'bluch')
40814081
elif operation == "delattr":
40824082
actual = self.get_suggestion(lambda: delattr(obj, 'bluch'))
4083-
4083+
else:
4084+
raise ValueError(f"operation '{operation}' not recognized")
4085+
40844086
self.assertIn(suggestion, actual)
40854087

40864088
def test_getattr_suggestions(self):
@@ -4102,6 +4104,8 @@ class A:
41024104
self.assertIn("'bluch'", self.get_suggestion(lambda: delattr(obj, 'blach')))
41034105
self.assertIn("'bluch'", self.get_suggestion(lambda: delattr(obj, '_luch')))
41044106
self.assertIn("'bluch'", self.get_suggestion(lambda: delattr(obj, '_bluch')))
4107+
else:
4108+
raise ValueError(f"operation '{operation}' not recognized")
41054109

41064110
class B:
41074111
_bluch = None
@@ -4120,6 +4124,8 @@ def method(self, name):
41204124
self.assertIn("'_bluch'", self.get_suggestion(lambda: delattr(obj, '_blach')))
41214125
self.assertIn("'_bluch'", self.get_suggestion(lambda: delattr(obj, '_luch')))
41224126
self.assertNotIn("'_bluch'", self.get_suggestion(lambda: delattr(obj, 'bluch')))
4127+
else:
4128+
raise ValueError(f"operation '{operation}' not recognized")
41234129

41244130
def test_getattr_suggestions_underscored(self):
41254131
self.run_underscored_tests("getattr")
@@ -4136,6 +4142,8 @@ class A:
41364142
actual = self.get_suggestion(obj, 'somethingverywrong')
41374143
elif operation == "delattr":
41384144
actual = self.get_suggestion(lambda: delattr(obj, 'somethingverywrong'))
4145+
else:
4146+
raise ValueError(f"operation '{operation}' not recognized")
41394147
self.assertNotIn("blech", actual)
41404148

41414149
def test_getattr_suggestions_do_not_trigger_for_long_attributes(self):
@@ -4155,6 +4163,8 @@ class MyClass:
41554163
actual = self.get_suggestion(MyClass, name)
41564164
elif operation == "delattr":
41574165
actual = self.get_suggestion(lambda: delattr(obj, name))
4166+
else:
4167+
raise ValueError(f"operation '{operation}' not recognized")
41584168
self.assertNotIn("Did you mean", actual)
41594169
self.assertNotIn("'vvv", actual)
41604170
self.assertNotIn("'mom'", actual)
@@ -4181,14 +4191,16 @@ class A:
41814191
actual = self.get_suggestion(obj, 'bluch')
41824192
elif operation == "delattr":
41834193
actual = self.get_suggestion(lambda: delattr(obj, 'bluch'))
4194+
else:
4195+
raise ValueError(f"operation '{operation}' not recognized")
41844196
self.assertNotIn("blech", actual)
41854197

41864198
def test_getattr_suggestions_do_not_trigger_for_big_dicts(self):
41874199
self.run_do_not_trigger_for_big_dicts_tests("getattr")
41884200

41894201
def test_delattr_suggestions_do_not_trigger_for_big_dicts(self):
41904202
self.run_do_not_trigger_for_big_dicts_tests("delattr")
4191-
4203+
41924204
def test_getattr_suggestions_no_args(self):
41934205
class A:
41944206
blech = None

0 commit comments

Comments
 (0)