Conformance: annotate module protocol globals#2318
Merged
carljm merged 1 commit intoJul 6, 2026
Merged
Conversation
The module protocol test should exercise structural compatibility without prescribing how type checkers infer unannotated module globals. Give the mutable attributes explicit public types so their protocol compatibility is unambiguous.
carljm
approved these changes
Jul 6, 2026
charliermarsh
added a commit
to astral-sh/ruff
that referenced
this pull request
Jul 7, 2026
Update the `python/typing` pin to the latest main. This picks up python/typing#2318, which annotates module protocol globals so the conformance test exercises structural compatibility without depending on inference for unannotated globals.
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.
This test is intended to verify that a module can implement a protocol when its public interface is compatible. As written, though, it also prescribes how type checkers infer the public types of unannotated module globals.
The protocol attributes here are mutable, so their types are invariant. Some type checkers widen an assignment like
one_flag = Truetoboolwhen accessed from another module, but in ty, we retainLiteral[True], in which case the attribute is not writable as an arbitrarybool.Explicitly annotating these variables as
intandboolmakes the intended public interface unambiguous (and should keep all existing implementations in-conformance).