Skip to content

New conformance tag '# E[tag!]' to require at least one success - #2354

Open
srittau wants to merge 8 commits into
python:mainfrom
srittau:one-success
Open

New conformance tag '# E[tag!]' to require at least one success#2354
srittau wants to merge 8 commits into
python:mainfrom
srittau:one-success

Conversation

@srittau

@srittau srittau commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Extracted from #2353.

Necessary for pyrefly, which accepts both assert_type(X, float) and assert_type(X, float | int), which other type checkers only accept either.

Not super happy with the syntax, any other suggestions welcome.

@davidhalter

Copy link
Copy Markdown
Collaborator

I don't mind this, but just so you know: I generally just tried to work around this by not using int in these scenarios and using str literals instead, which don't have the promotion issues. In your specific case I might have used:

bare3: Final = [1]  # infer bare3 as Final[list[int]]

I don't think that the promotion details matter for readers of the spec.

@carljm carljm left a comment

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.

This seems fine to me as a tool to have, though like @davidhalter I suspect that there is a better way to address the motivating case (we should always avoid using float as part of conformance suite examples, unless those examples are explicitly about the int/float special case) -- and if that leaves us with no use case for this, then it probably doesn't make sense to add it now.

Comment thread conformance/README.md Outdated
* `# 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.
* `# E[tag+]`: like `# E[tag]`, but errors may be raised on multiple lines.
* `# E[tag!]`: like `# E[tag]`, but at least one line must not raise an error.

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.

We should say explicitly here that zero errors also pass.

Comment thread conformance/src/main.py
]:
"""Return the line numbers where type checkers are expected to produce an error.

The return value is a tuple of two dictionaries:

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.

This docstring needs updating.

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.

I'm also thinking about replacing the second tuple item with either a string literal or an enum "single", "multiple", "require-success". This would make a cleaner API and make it more obvious that these three options are basically mutually exclusive. What do you think?

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.

Oh sorry I accidentally made a separate comment instead of replying here. If there are really just three supported/useful options, then I think an enum would be better than two booleans. (Better than using strings, too.)

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.

I've introduced the enum, extracted the logic that makes a decision based on this enum, and simplified the logic so that it should be obvious what's going on. The output doesn't change, indicating that the logic is (still) correct.

srittau and others added 7 commits September 2, 2026 13:26
-  Introduce an `ErrorMultiplicity` enum and return it from
  `get_expected_errors()`.
- Extract `determine_group_error()` from `diff_expected_errors()` and
  simplify logic.
- Rerun black on `main.py`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants