Add tests for `Final`/`Literal` interaction by srittau · Pull Request #2352 · python/typing · GitHub
Skip to content

Add tests for Final/Literal interaction - #2352

Closed
srittau wants to merge 7 commits into
python:mainfrom
srittau:conformance-final
Closed

Add tests for Final/Literal interaction#2352
srittau wants to merge 7 commits into
python:mainfrom
srittau:conformance-final

Conversation

@srittau

@srittau srittau commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

This is my first time changing the conformance tests, did I do it correctly? What does "conformant is required when conformance_automated is 'Fail'" mean?

Also cf. #2351. If that issue and this PR is accepted I would like to add quotes from the (changed) spec to the tests before merging this.

@carljm

carljm commented Aug 31, 2026

Copy link
Copy Markdown
Member

# Specification: https://typing.readthedocs.io/en/latest/spec/qualifiers.html#id1

ID1: Final[int] = 1
assert_type(ID1, Literal[int])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Literal[int] is not a valid type expression (and thus every type checker correctly errors on it). Same with Literal[float] below.

Did you mean to assert the type is just int? If so, I don't think that's an assertion supported by the spec. https://typing.python.org/en/latest/spec/literal.html#interactions-with-final explicitly says that in this exact scenario, an inference of either int or Literal[1] is fine.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Interesting, another contradiction in the spec.

@carljm

carljm commented Aug 31, 2026

Copy link
Copy Markdown
Member

What is your intention for this PR vs #2353 ? I think it would be simpler and preferable to just have one combined PR that modifies both the spec text and the conformance suite, rather than two separate PRs.

@srittau srittau added the topic: conformance tests Issues with the conformance test suite label Aug 31, 2026
@srittau

srittau commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator Author

What is your intention for this PR vs #2353 ? I think it would be simpler and preferable to just have one combined PR that modifies both the spec text and the conformance suite, rather than two separate PRs.

Sure, I can combine them if you prefer. Considering that both are more or less independent (since the are only refactorings/documentation of the status quo) I thought it would be easier to review separately.

@carljm

carljm commented Aug 31, 2026

Copy link
Copy Markdown
Member

I don't have strong feelings; if you prefer to separate them, that's fine. I would personally find it easier to review them together; it makes it easier to validate that we have the right tests for the clarified spec text.

@srittau

srittau commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator Author

@srittau srittau closed this Aug 31, 2026
@srittau
srittau deleted the conformance-final branch August 31, 2026 18:55
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.

2 participants