From e5bb8f9a848cae3134f2319f5a131b5ca083c344 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Tue, 27 Sep 2022 17:52:15 -0400 Subject: [PATCH] Favor human readers over mypy --- src/twisted/trial/runner.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/twisted/trial/runner.py b/src/twisted/trial/runner.py index 5bc75de41a7..ffc554e25c8 100644 --- a/src/twisted/trial/runner.py +++ b/src/twisted/trial/runner.py @@ -286,13 +286,19 @@ def name(thing: _Loadable) -> str: """ if isinstance(thing, pyunit.TestCase): return thing.id() - elif isinstance(thing, (modules.PythonAttribute, modules.PythonModule)): + + if isinstance(thing, (modules.PythonAttribute, modules.PythonModule)): return thing.name - elif isTestCase(thing): + + if isTestCase(thing): # TestCase subclass return reflect.qual(thing) - else: - assert False + + # Based on the type of thing, this is unreachable. Maybe someone calls + # this from un-type-checked code though. Also, even with the type + # information, mypy fails to determine this is unreachable and complains + # about a missing return without _something_ here. + raise TypeError(f"Cannot name {thing!r}") def isTestCase(obj: type) -> TypeGuard[Type[pyunit.TestCase]]: