Skip to content

Make join of callables a bit more principled - #22296

Open
ilevkivskyi wants to merge 3 commits into
python:masterfrom
ilevkivskyi:typ-obj-join
Open

ilevkivskyi wants to merge 3 commits into
python:masterfrom
ilevkivskyi:typ-obj-join

Conversation

@ilevkivskyi

@ilevkivskyi ilevkivskyi commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #9756
Fixes #10160
Fixes #13182
Fixes #14443

This is needed to de-risk #22286

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks good!

def __init__(self, *, x) -> None: ...
class C2(B): ...

x = [C1, C2]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
x = [C1, C2]
x = [C1, C2]
reveal_type(x)
from typing import TypeVar
T = TypeVar("T")
def join(a: T, b: T) -> T: ...
reveal_type(join(C1, C2))

@github-actions

This comment has been minimized.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

Btw it looks like this fixes 3 existing issues, updated PR description. The homeassistant error are bizarre, need to investigate. Error in sympy means we still can infer a join that is not a supertype of one of the items, may need some more tightening. The rest is likely because we handle argument names in lambdas incorrectly.

@github-actions

This comment has been minimized.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

Errors in pandera are somewhat unfortunate, but are actually consistent. Mypy uses surrounding items in a list to infer type of lambdas. In their case they should have used a list of tuples as an argument to pytest.mark.parameterize(), not a list of lists.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

Actually something is fishy there, I will dig more deeply.

@ilevkivskyi

Copy link
Copy Markdown
Member Author

OK, this uncovered inconsistency in ignore_pos_arg_names: it randomly stops working in some cases. For example, if left and right have an argument with the same name in different positions. But this is a rabbit hole where I don't want to go.

I think I will add a workaround for now with saying that meet(Any, X) is Any for the purpose of argument types (it should be the case in general, but this is yet another rabbit hole).

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants