conformance: fix generics_defaults — flag ParamSpec-after-TypeVarTuple when TVT has no default#2310
Open
ashishpatel26 wants to merge 2 commits into
Conversation
…le without TVT default
The conformance test for `class Foo6(Generic[*Ts, P])` was missing an
`# E` marker. The spec only permits a defaulted `ParamSpec` to follow a
`TypeVarTuple` when the `TypeVarTuple` **also has a default**; in the
test `Ts` had no default, so the class is ambiguous (exactly like the
`TypeVar`-after-`TypeVarTuple` rule) and raises `TypeError` at runtime.
Changes:
- Add `TsD = TypeVarTuple("TsD", default=Unpack[tuple[int, str]])` for
the valid case.
- Mark `class Foo6(Generic[*Ts, P])` as `# E` (Ts has no default).
- Add `class Foo6b(Generic[*TsD, P])` as the spec-valid case (both
`TsD` and `P` have defaults) with corresponding assertions.
- Clarify the spec prose to state the "TypeVarTuple **with a default**"
condition explicitly and show a counter-example.
- Update all six checker result TOMLs.
Fixes: python#2211
Collaborator
|
This is probably something where the spec was just not worded well enough. There is kind of an implicit default for type var tuples in this case, which is the empty tuple. I don't think the changing the conformance tests makes sense here. |
Member
|
the consensus in the issue seemed to be that it's a bug in CPython that we should fix there |
pyrefly, pyright, and zuban were missing `conformant = "Partial"` after conformance_automated changed from Pass to Fail. The validate_results script requires conformant to be explicitly set when automated is Fail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2211.
The spec states that a
ParamSpecwith a default may follow aTypeVarTupleonly when theTypeVarTuplealso has a default (to avoid ambiguity). The existing conformance testclass Foo6(Generic[*Ts, P])hadTswithout a default but was missing an# Emarker, effectively telling type checkers to accept code that raisesTypeErrorat runtime.Changes:
conformance/tests/generics_defaults.pyTsD = TypeVarTuple("TsD", default=Unpack[tuple[int, str]])for the valid case.class Foo6(Generic[*Ts, P])as# E—Tshas no default, so this is ambiguous.class Foo6b(Generic[*TsD, P])(no error) — bothTsDandPcarry defaults.test_foo6(which exercised the now-invalid class) withtest_foo6b.docs/spec/generics.rstclass Bar[*Ts, **P = [float, bool]]: ... # Type checker error.conformance/results/*/generics_defaults.toml— updated for all six checkers.Test plan
conformance/tests/generics_defaults.pychanges reviewed for correctness./)