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

Experiment with intersection on TypeVars #15712

Closed

Conversation

A5rocks
Copy link
Contributor

@A5rocks A5rocks commented Jul 18, 2023

While working on #15711 and reflecting, I had a thought about how the upper bound on T is essentially an intersection: T with an upper bound of int is kinda somewhat T & int.

This means T & int & <something> is essentially T & (int & <something>). I implemented this, I want to see how mypy primer looks.

@github-actions

This comment has been minimized.

@A5rocks
Copy link
Contributor Author

A5rocks commented Jul 19, 2023

I think the only (wow, that's surprising) error is genuine. I guess I'll actually flesh out this PR, weird.

@github-actions

This comment has been minimized.

@A5rocks A5rocks marked this pull request as ready for review July 19, 2023 01:00
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/datastructures/structures.pyi:137: error: Overloaded function signatures 2 and 3 overlap with incompatible return types  [misc]

@A5rocks
Copy link
Contributor Author

A5rocks commented Jul 19, 2023

I don't understand the test failures. I can't reproduce them either on Linux or Windows.

Copy link
Contributor Author

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for when I'm not on mobile

Comment on lines +685 to +687
# this may be alright on things other than just instances
elif isinstance(self.s, (Instance, NoneType, TupleType)):
return t.copy_modified(upper_bound=meet_types(t.upper_bound, self.s))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: there's probably a "is concrete type" utility somewhere in mypy. Maybe in checking for subtypes of type.

elif isinstance(self.s, LiteralType):
return meet_types(t, self.s)
elif isinstance(self.s, TypedDictType):
elif isinstance(self.s, (TypeType, TupleType, LiteralType, TypedDictType, TypeVarType)):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: check every visit method to make sure typevars are getting passed through.

@A5rocks
Copy link
Contributor Author

A5rocks commented Jun 16, 2024

Maybe I'll look at this more some day.

@A5rocks A5rocks closed this Jun 16, 2024
@A5rocks A5rocks deleted the experiment-with-typevar-intersection branch June 16, 2024 04:00
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

Successfully merging this pull request may close these issues.

1 participant