chore: changes for mypy update #191
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Fixes: #179
What was the problem/requirement? (What/Why)
See https://github.com/OpenJobDescription/openjd-adaptor-runtime-for-python/actions/runs/14341779725/job/40202541223?pr=179
A mypy update detected some issues.
What was the solution? (How)
Be more precise in the code with typing. There were a couple function calls that had mis-matched types.
In
model.pyreassert what we know to be true about the type.In
_configuration_manager.pythe type in the function argument was actually incorrect. We wanted the class type, not an instance.I also found a kind of bug in
DataclassMapper. We were never actually reaching the code that maps an enum value to an enum. Now in practice this didn't matter because we were using string enums and the underlying data we were checking is the same whether or not the value is an enum. However this wasn't the intent of the code, we wanted an accurate mapping to the enum.The issue was that we were checking if the field was a subclass of
Enum. The typing stuff gets kinda confusing here, the enum field type is actuallyEnumMeta, which isn't a subclass ofEnum.It's called
EnumTypein Python >= 3.11, we'll useEnumMetafor backward compatibility asEnumMetais an alias forEnumTypein Python >= 3.11So now we check if the field is an
EnumMeta. The code afterwords could be simplified quite a bit after we know that it's anEnumas well.What is the impact of this change?
More accurate typing, hopefully more robust code.
How was this change tested?
hatch run testI also added tests for mapping
Enumsas these were missing before.Yep
Was this change documented?
Nothing to document.
Ya, this doesn't impact any of the public APIs.
Is this a breaking change?
No
Does this change impact security?
No
No
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.