-
Notifications
You must be signed in to change notification settings - Fork 382
add type hints #1343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
add type hints #1343
Conversation
Converting old docstring-based type hints to PEP 484 type hints. This commit includes all of cms/ except for cms/server/, and all of cmscommon/.
@gollux is the python 3.12 minimum version requirement likely to be a problem for IOI? |
This IOI will run on Ubuntu 2024.04.02 with Python 3.12.3. However, I would prefer requiring at least 3.11, because that's in stable Debian, which is sort of the lower bound for all reasonable Linux distros ;) What feature from 3.12 do you need? |
the new type parameter syntax. i also wanted to use typing.override, but couldn't be bothered with it (there's a few functions where the return type depends on a boolean argument, using (edit: brain fart, i meant it's okay, i'll just replace it with manual typing.TypeVar usage. we might want to also run tests on the oldest version of python we want to support. |
Tests now pass on python 3.11 aswell. I'll make a separate PR later to automatically test this on github actions, for now i'm testing on 3.11 locally. |
Added type hints to cms/server and fixed some previous type hint mistakes.
guard all tornado imports behind `if typing.TYPE_CHECKING`. i think this allows the "tornado4" workaround to still work, though i don't know if it's relevant anymore.
some more notes: for cmsranking and cmscontrib i tried to add type hints to all functions, even where they weren't present before. for cmstestsuite i only converted the old type hints to new-style ones. there's a few modules where it would be possible to have much better static typing if the code was refactored a bit. currently i tried to keep the existing code untouched. (though i added a few asserts that should always be true, in cases where there's some complicated control flow and the type checker can't figure out that something is always not-None.) the web server parts had less type hints than i expected; this is mostly because a lot of it is just passing parameters into jinja templates which are, again, completely untyped. A lot of the remaining type errors are about sqlalchemy queries, which could be fixed by upgrading to sqlalchemy 2.0 (i think). I might try that at some point. The rest are in tornado/werkzeug/jinja, and as i understand, upgrading those is quite the ordeal. But I suppose it must still happen some day. And there's also a lot of type errors about missing None checks, most of them false positives, some of them quite certainly real :) |
Converting old docstring-based type hints to PEP 484 type hints. Current progress: all of cms/ except for cms/server/, and all of cmscommon/.
Notes:
other_service.rpc.method(args)
(as opposed to the currentother_service.method(args)
).