Skip to content

Conformance suite: Minor tweaks to several assertions for better compatibility with ty#2178

Open
AlexWaygood wants to merge 6 commits intomainfrom
alex/fewer-test-assumptions
Open

Conformance suite: Minor tweaks to several assertions for better compatibility with ty#2178
AlexWaygood wants to merge 6 commits intomainfrom
alex/fewer-test-assumptions

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Feb 16, 2026

This PR makes several tweaks to the conformance suite to resolve issues where ty would appear to be failing assertions the conformance suite makes. In reality, all of the locations edited in this PR appear to be causing ty failures due to the fact that the suite was making overly specific assertions that made undue assumptions.

These are all minor changes that do not change the intent of the tests, so I've bundled them together.

@AlexWaygood AlexWaygood added the topic: conformance tests Issues with the conformance test suite label Feb 16, 2026
T = int(0)


class Outer2[T]:
Copy link
Member Author

Choose a reason for hiding this comment

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

the assertions in this test ran into issues because ty inferred T as having type Literal[""] where T = str("").

ty also rejected the assert_type(T, complex) call lower down after the T = 3j assignment, because we view complex in a type expression as immediately expanding to the union int | float | complex, and the second argument to assert_type takes a type expression -- but complex (the type inferred for T) is not equivalent to int | float | complex.

@AlexWaygood
Copy link
Member Author

I'll revert the changes to the defaults-related tests for now, since they're clearly a bit more problematic than the others, but this PR was intended to bundle together several relatively uncontroversial changes

Comment on lines -193 to +195
assert_type(generator30, Callable[[], AsyncIterator[int]])
async def uses_generator30() -> None:
async for x in generator30():
assert_type(x, int)
Copy link
Member Author

@AlexWaygood AlexWaygood Feb 16, 2026

Choose a reason for hiding this comment

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

ty infers a "function-literal" type for generator30, not a Callable type. A function-literal type is more precise than a Callable type: it retains, for example, the information that generator30 is an instance of types.FunctionType, which is not true for all arbitrary Callable types.

I don't believe the spec states anywhere that type checkers must infer a Callable type for function objects (only that functions must be considered to inhabit Callable types), so I think this change is appropriate.

I tried doing just assert_type(generator30(), AsyncIterator[int]), but then zuban (reasonably) complained that the result of generator30() was never awaited, which wasn't relevant to what the test was trying to assert.

@AlexWaygood AlexWaygood marked this pull request as ready for review February 16, 2026 01:27
Comment on lines 15 to 16
assert_type(fun_1(1), int) # E[fun1-int]
assert_type(fun_1(1), Literal[1]) # E[fun1-int]
Copy link
Member

Choose a reason for hiding this comment

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

How does the conformance checker handle it if there's an error on both of these lines? It's the intent of the test that that should be considered non-conforming.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe a tagged error like this is still non-optional: an error must be emitted on at least one of these lines. This seems to be reflected by the fact that zuban is no longer considered conformant on this PR branch, if you look at the changes to the reported results -- it apparently doesn't emit an error on either of these lines. (That seems like a bug in zuban to me -- int and Literal[1] are not equivalent types, so fun_1(1) cannot be equivalent to both int and Literal[1].)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, as per https://github.com/python/typing/tree/main/conformance#test-case-syntax:

# E[tag], where tag is an arbitrary string: must appear multiple times in a file with the same tag. Exactly one line with this tag must raise an error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

cc @davidhalter - FYI this conformance change turned up what looks like a bug in zuban.

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

Labels

topic: conformance tests Issues with the conformance test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants