Skip to content

Prevent registering type handlers using types that have specified generics (Dict is okay, Dict[str, int] is not)#246

Merged
56kyle merged 6 commits intodevelopfrom
feature/restrict-handler-registration-with-generics
May 9, 2025
Merged

Prevent registering type handlers using types that have specified generics (Dict is okay, Dict[str, int] is not)#246
56kyle merged 6 commits intodevelopfrom
feature/restrict-handler-registration-with-generics

Conversation

@56kyle
Copy link
Owner

@56kyle 56kyle commented May 9, 2025

Since there is a ton of complexity involved with supporting proper sub type checking for custom registered type sets, for now the plan is to block off the edge case until it becomes an issue.

For example, if I were to run the following:

from pytest_static.parametric import type_handlers

@type_handlers.register(Dict[str, int | str])
def my_instances(base_type: Any, type_args: tuple[Any, ...]) -> Dict[str, int | str]:
    ...

I would get a TypeError because I gave Dict[str, int | str] as the type to register instead of just Dict.

Ideally in the future this would be perfectly fine and we just match based on whether the current base type + type args are a sub type of the key you provided, but it adds another layer to the issues we are having by taking the cartesian product of possibilities. This might not be as big of a problem down the line if the project can use maturin or if we can find a way to reduce the slow nature of pytest making tests with pytester in the tests for pytest-static. In short performance comes first and this is worth the sacrifice for the time being.

…based on a type containing a pre-specified generic
@56kyle 56kyle self-assigned this May 9, 2025
@56kyle 56kyle added breaking Breaking Changes python Pull requests that update Python code and removed breaking Breaking Changes labels May 9, 2025
56kyle and others added 5 commits May 8, 2025 22:15
@56kyle 56kyle merged commit 8879ee1 into develop May 9, 2025
36 checks passed
@56kyle 56kyle deleted the feature/restrict-handler-registration-with-generics branch May 9, 2025 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant