Skip to content

Resolve ... vs EllipsisType asymmetry - #4510

Open
alexander-beedie wants to merge 1 commit into
facebook:mainfrom
alexander-beedie:ellipsis-narrowing
Open

Resolve ... vs EllipsisType asymmetry#4510
alexander-beedie wants to merge 1 commit into
facebook:mainfrom
alexander-beedie:ellipsis-narrowing

Conversation

@alexander-beedie

@alexander-beedie alexander-beedie commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #4426.

Overview

  • Python has one ellipsis object that can be written two ways: as literal ..., or types.EllipsisType.

  • pyrefly represents these with two different internal types, but there's an asymmetry in terms of which can be assigned to which (this is the root cause).

  • Specifically: the value ... is inferred as Type::Ellipsis, but a types.EllipsisType annotation is inferred as ClassType(EllipsisType), and assignability between the two holds in only one direction.

Solution

  • Add the missing/reverse assignability arm.

  • Ensure literal_equal recognises both representations.

Test Plan

  • Unit test suite was run, and a new test was added.

  • Was able to remove the error markers from:

    • test_ellipsis_is
    • test_ellipsis_eq

    Updated these tests to use assert_type as that validates equivalence, rather than matching substrings of the printed type (as per reveal_type).

@meta-codesync

meta-codesync Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D115576310. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on open source code:

xarray (https://github.com/pydata/xarray)
- ERROR xarray/core/dataset.py:8354:24-27: Argument `Collection[Hashable] | EllipsisType` is not assignable to parameter `iterable` with type `Iterable[Hashable]` in function `set.__init__` [bad-argument-type]
- ERROR xarray/core/groupby.py:1049:32-35: Argument `Collection[Hashable] | EllipsisType` is not assignable to parameter `iterable` with type `Iterable[Hashable]` in function `tuple.__new__` [bad-argument-type]
- ERROR xarray/core/utils.py:1025:25-28: Argument `Collection[Hashable] | EllipsisType | tuple[str]` is not assignable to parameter `iterable` with type `Iterable[Hashable]` in function `set.__init__` [bad-argument-type]
- ERROR xarray/core/utils.py:1026:18-21: Argument `Collection[Hashable] | EllipsisType | tuple[str]` is not assignable to parameter `iterable` with type `Iterable[Hashable]` in function `tuple.__new__` [bad-argument-type]
- ERROR xarray/core/utils.py:1064:15-18: Argument `Collection[Hashable] | EllipsisType | set[Hashable]` is not assignable to parameter `iterable` with type `Iterable[Hashable]` in function `set.__init__` [bad-argument-type]
- ERROR xarray/core/utils.py:1122:76-86: `in` is not supported between `Ellipsis` and `EllipsisType` [not-iterable]
- ERROR xarray/core/utils.py:1123:54-57: Argument `Collection[Hashable] | EllipsisType` is not assignable to parameter `iterable` with type `Iterable[Hashable]` in function `set.__init__` [bad-argument-type]
- ERROR xarray/core/utils.py:1129:22-25: Argument `Collection[Hashable] | EllipsisType` is not assignable to parameter `iterable` with type `Iterable[Hashable]` in function `tuple.__new__` [bad-argument-type]

@rchen152 rchen152 self-assigned this Aug 11, 2026
@rchen152

Copy link
Copy Markdown
Contributor

Thanks for the PR! In the future, would you mind first checking if the issue is already assigned and claiming it if it's free? (Don't worry about this PR, though; it looks like it should be pretty easy for me to reconciliate this with my in-progress work.)

@alexander-beedie

alexander-beedie commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the PR! In the future, would you mind first checking if the issue is already assigned and claiming it if it's free?

Ahh, apologies; I'm still not quite used to that... Have claimed one or two properly, but forgot here -- will make sure to do so on the next one! 😅👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Narrowing against Ellipsis token is broken.

2 participants