Document how joins work

Open
#5,219 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
documentation

Research direction

Start by locating the mypy documentation covering type inference for collections and related typing behavior. Use the A, B, and C example from the issue to verify how inferred common base classes differ from an explicitly annotated Union. Done means the behavior is explained with accessible examples without relying heavily on the term “join”.

Written by the indexing model from the issue text.

Description

documentation priority-1-normal topic-join-v-union

Joins tend to produce common base classes instead of unions, and this may be surprising. I don't think that this is documented, at least not very clearly. The discussion probably shouldn't rely heavily on the relatively obscure term "join" (especially as the operation technically isn't quite a lattice join) -- rather we can use examples and more informal explanations.

Typical example where this is relevant:

class A: pass
class B(A): pass
class C(A): pass

x = [B(), C()]  # Inferrred type List[A], not List[Union[B, C]]
y: List[Union[B, C]]
y = [B(), C()]  # Now the type is List[Union[B, C]]
Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 18h
Merged PRs (30d)
54

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.