python / python/mypy

Inconsistent constraint resolution for tuples.

Open
#19,860 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-pep-646
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Adding the following test to ConstraintsSuite fails with assert set() == {1 <: B, 1 <: A}:

    def test_wrapped_tuple_identical_results(self) -> None:
        # test inferred constraints of tuple[T, ...] <: tuple[A, B]
        # vs inferred constraints of tuple[*tuple[T, ...]] <: tuple[A, B]
        fx = self.fx
        t = Instance(fx.std_tuplei, [fx.t])
        assert set(infer_constraints(
            t,
            TupleType([self.fx.a, self.fx.b], fallback=self.fx.std_tuple),
            SUBTYPE_OF,
        )) == set(infer_constraints(
            TupleType([UnpackType(t)], fallback=self.fx.std_tuple),
            TupleType([self.fx.a, self.fx.b], fallback=self.fx.std_tuple),
            SUBTYPE_OF,
        ))

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.

Research direction

Start in ConstraintsSuite with test_wrapped_tuple_identical_results and inspect infer_constraints for the two tuple forms shown. Reproduce the assertion, then make both calls infer identical constraints and rerun the focused ConstraintsSuite test to confirm it passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.