Preserve call arguments of generate_packet_map #170
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.
The generate_packet_map function is using
functools.lru_cache
to preserve the results, however this decorator returns a_lru_cache_wrapper
type, which only preserves the return type from the original function, without preserving call arguments (or overloads).This overrides
lru_cache
function duringTYPE_CHECKING
, and gives it a signature that preserves this information. This does however mean losing on the information that this function is cached, however for us, it's much more important to preserve call parameters and overloads so that calls to it are actually checked.So while this is absolutely a hack and it's not ideal, it's the lesser evil when the alternative is losing on the type info from all parameters.