Skip to content

Narrow TypeVars in the negative case + narrow them through upper bounds #15711

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

Closed
wants to merge 2 commits into from

Conversation

A5rocks
Copy link
Collaborator

@A5rocks A5rocks commented Jul 18, 2023

While the second part of this (upper bound narrowing) could be another
PR, I believe it's the better state for the initial PR and it's not much
extra work.
@github-actions

This comment has been minimized.

@eltoder
Copy link

eltoder commented Jul 19, 2023

Another PR with a similar fix: #15377
@ikonst FYI

@A5rocks
Copy link
Collaborator Author

A5rocks commented Jul 19, 2023

Oops. That other PR has a nicer printing of stuff. Maybe I should stick to only narrowing in the negative case.

Copy link
Contributor

github-actions bot commented Jan 4, 2024

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

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/coretypes/serializable.py:186: error: Unused "type: ignore" comment  [unused-ignore]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/commands.py:287: error: Argument 1 to "append" of "list" has incompatible type "Command[Any, Any, Any]"; expected "Self"  [arg-type]
- steam/ext/commands/commands.py:940: error: Incompatible return value type (got "Command[Any, Any, Any] | MaybeCommandT", expected "MaybeBool | MaybeCommandT")  [return-value]

mypy (https://github.com/python/mypy)
+ mypy/typeops.py:342: error: Incompatible types in assignment (expression has type "CallableType", variable has type "F")  [assignment]

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ tests/__init__.py:30: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/__init__.py:44: error: Unused "type: ignore" comment  [unused-ignore]

@ilevkivskyi
Copy link
Member

I propose to close this in favor of #19183 that offers a different approach.

@A5rocks A5rocks deleted the fix-negative-typevar-narrowing branch May 31, 2025 21:31
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.

Narrowing doesn't work on a typevar with a union bound TypeVar error
4 participants