Skip to content
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

Add mypy check, fix types #512

Merged
merged 4 commits into from
Feb 19, 2025
Merged

Add mypy check, fix types #512

merged 4 commits into from
Feb 19, 2025

Conversation

lossyrob
Copy link
Contributor

@lossyrob lossyrob commented Feb 19, 2025

This adds mypy checks to scripts/lint.sh

Runs mypy over ossdbtoolsservice and tests_v2 directories, except for ossdbtoolsservice.language.completion module. That module proved very hard to type without breaking the code, so it's left untyped for now. Other modules like smo and pgsmo are left untyped, as well as tests.

Generally, the goal here was to leave functionality unchanged. However in order to fix types I did need to refactor a number of things. However this should be transparent to the consumer, except that error messages in cases where required values are not sent should be more clear.

One functionality change made was that the SaveAsJsonWriter was serializing all values as strings; I modified to check if it's a serializable type and if so serialize the direct value.

Another strategy was to de-abstract the project away from supporting multiple open source DBs when convenient. There is no actual implementation for other DBs, and this is a PG specific project; the concept of different provider types in the codebase is simply a maintenance burden.
 
A lot of changes were due to the way the message models were created, with Serializable objects needing a parameterless __init__. This required a lot of validation around if properties were None throughout the handler code. Going forward we should only use pydantic.BaseModel models to ensure validation happens up front and we can write code against the intended property types. Pydantic model support is already implemented in the MessageServer.

There's a lot of # noqa comments around the codebase without a good reason to no QA; this PR removes a lot of them and we should keep deleting those whenever we see them without justification.

Otherwise ruff check can fail on things ruff format fixes.
Only runs over ossdbtoolsservice and tests_v2. Does not follow imports, which would end up checking other projects. This is to scope the linting to where new development will happen.

Skips checking ossdbtoolsservice.language.completion. This module was particularly tricky to fix with typing. Could be tackled in future, but for now allow this to continue to be untyped.
@lossyrob lossyrob requested review from a team as code owners February 19, 2025 00:31
@lossyrob lossyrob force-pushed the feature/rde/mypy-type-checking branch from 224bc93 to 94f1c82 Compare February 19, 2025 05:20
@lossyrob lossyrob merged commit 142bd72 into main Feb 19, 2025
2 checks passed
@lossyrob lossyrob deleted the feature/rde/mypy-type-checking branch February 19, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants