Skip to content

Conformance: minor update to LiteralString tests#2179

Open
sharkdp wants to merge 1 commit intopython:mainfrom
sharkdp:update-literalstring-tests
Open

Conformance: minor update to LiteralString tests#2179
sharkdp wants to merge 1 commit intopython:mainfrom
sharkdp:update-literalstring-tests

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Feb 16, 2026

I ran into this while looking at ty's conformance results. For an expression like str(1), ty infers Literal["1"]. It can therefore infer that some_literal_str + str(1) is also of type LiteralString. The conformance suite asserts the opposite (that the result should be of type str), based on the assumption that str(1) is definitely of type str.

The updated code also seems like a readability-improvement to me, as there is now just one way to refer to a non-LiteralStr object (instead of three different expressions).

The updates here only lead to line-number changes in the results for all type checkers.

I ran into this while looking at ty's conformance results. For an
expression like `str(1)`, ty infers `Literal["1"]`. It can therefore
infer that `some_literal_str + str(1)` is also of type `LiteralString`.

The conformance suite asserts the opposite (that the result should be of
type `str`), based on the assumption that `str(1)` is definitely of type
`str`.

The updated code also seems like a readability-improvement to me, as
there is now just one way to refer to a non-`LiteralStr` object.

The updates here only lead to line-number changes in the results for
all type checkers.
Copy link
Member

@carljm carljm left a comment

Choose a reason for hiding this comment

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

I agree that a type-checker should not be prevented from inferring a literal string type from str() passed a literal argument.

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.

5 participants