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

CLEAN: Investigate whether any TypeVar that constraints to a list of types can change to being bound to a Union #719

Open
Dr-Irv opened this issue May 29, 2023 · 0 comments

Comments

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented May 29, 2023

See comment 3 in microsoft/pyright#5178 (comment)

The pd.Series class is making use of a constrained TypeVar. I'm not sure why this was done, but it's almost certainly not the right approach. A constrained TypeVar is rarely the right tool — and that's especially true when it comes to class-scoped type variables. There are many reasons why a constrained TypeVar is problematic, but to give you one example... A Series is able to contain heterogeneous types, but a constrained TypeVar doesn't permit something like Series[int | str]. I recommend that you switch from a constrained TypeVar to a regular TypeVar with a bound that is a union. Not only will this more correctly model the way Series works in pandas, it will also avoid the many bugs that mypy has with constrained TypeVars. I see that constrained TypeVars are used in a number of locations within the pandas stubs. I recommend looking at each of these uses and considering whether there's a better approach.

We should investigate whether we can change all TypeVar that have a list of types to refer to a Union of those types instead, with the bound argument. It works fine for S1 in #716

@Dr-Irv Dr-Irv mentioned this issue May 30, 2023
2 tasks
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

1 participant