webui: NameError: name 'ServerType' is not defined #619
Closed
Description
the type annotations added in webui refactoring at f9534e2 throws a missing name exception when running with pyglossary --web
:
File "/Users/12345/projects/python/pyglossary/pyglossary/ui/ui_web/__init__.py", line 1, in <module>
from pyglossary.ui.ui_web.ui_controller import WebUI as UI
File "/Users/12345/projects/python/pyglossary/pyglossary/ui/ui_web/ui_controller.py", line 11, in <module>
from pyglossary.ui.ui_web.websocket_main import create_server
File "/Users/12345/projects/python/pyglossary/pyglossary/ui/ui_web/websocket_main.py", line 35, in <module>
from pyglossary.ui.ui_web.weblog import WebLogHandler
File "/Users/12345/projects/python/pyglossary/pyglossary/ui/ui_web/weblog.py", line 36, in <module>
class WebLogHandler(logging.Handler):
File "/Users/12345/projects/python/pyglossary/pyglossary/ui/ui_web/weblog.py", line 37, in WebLogHandler
def __init__(self, server: ServerType) -> None:
^^^^^^^^^^
NameError: name 'ServerType' is not defined
One way to fix would be to make imports unconditional and remove if TYPE_CHECKING
condition, or (the fix I applied in my local env) to use string annotations, ie. instead of def __init__(self, server: ServerType)
use def __init__(self, server: "ServerType")
. Was going to make a pull request with this change but then saw that ruff complains with Found 109 errors.
(with mostly cosmetic stuff), so maybe you have a better way?