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

List and other invariant types should behave covariantly on runtime typechecking #76

Open
Stewori opened this issue Aug 29, 2019 · 3 comments

Comments

@Stewori
Copy link
Owner

Stewori commented Aug 29, 2019

For runtime typechecking deep_type is used to determine the PEP 484 type of a given object. Then is_subtype is used to detect if the type is acceptable. E.g. [2] is considered List[int] by deep_type although it could also be List[float] or List[Union[int, whatever]].

Solution idea:
Widen the use of Empty which is currently used to handle [] and {}, etc.
It would be renamed to Sampled or so and serve as a marker type for is_subtype to check its contained type, e.g. Sampled[List[int]] in covariant manner even if it is actually invariant.

@jolaf
Copy link

jolaf commented Aug 30, 2019

Sounds cool, thank you!

@jolaf
Copy link

jolaf commented Aug 30, 2019

I wonder if this Sampled[] and Empty[] things should be visible in TypeWarning printout when actual type mismatch occurs.

Probably they are better to be removed at printing to not confuse the user.

@Stewori
Copy link
Owner Author

Stewori commented Aug 30, 2019

Yes that's right. Or at least invisible unless some debug flag is set. I would cure this in type_str. However this won't fix before Python 3.7 compatibility is achieved because it requires some broader restructuring. I have rather limited capacity to tackle these bigger changes.

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

No branches or pull requests

2 participants