Improve ellipsis type
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- documentation, tooling
Research direction
The issue names no implementation files or tests; start by locating the current ellipsis definition and the Markdown documentation that describes it. Check Python-version compatibility and type-checking behavior, then confirm that the chosen representation is documented clearly and rejects non-Ellipsis arguments as intended.
Written by the indexing model from the issue text.
Description
The current ellipsis = TypeVar('ellipsis') doesn't behave well with typechecking. It's also unclear in the Markdown docs what ellipsis is supposed to be. It's kind of clear from the context, but not compatible with "real" python types:
from types import EllipsisType
from typing import Protocol, TypeVar
ellipsis = TypeVar('ellipsis') # This is the current implementation.
class BadProto(Protocol):
def f(self, ell: ellipsis) -> None: ... # Error: TypeVar "ellipsis" appears onlly once in generic function signature
class GoodProto(Protocol):
def f(self, ell: EllipsisType) -> None: ... # Ok, no error raised.
def some_bad_operation(x: BadProto) -> None:
x.f('hello') # Problematic: doesn't raise a type error.
def some_good_operation(x: GoodProto) -> None:
x.f('hello') # Good, raises:
# [Pyright] Argument of type "Literal['hello']" cannot be assigned to parameter "ell" of type "EllipsisType" in function "f"
# "Literal['hello']" is incompatible with "EllipsisType"
The downside of EllipsisType is that it's only available in Python 3.10 onwards. However, we have the following:
assert EllipsisType == type(...)
assert EllipsisType == type(Ellipsis)
assert EllipsisType != ...
assert EllipsisType != Ellipsis
assert ellipsis != Ellipsis # with ellipsis = TypeVar('ellipsis')
It seems to me like it would make sense to change the current ellipsis = TypeVar('ellipsis') to one of the variants that works. I think it would also be a clarification in the documentation to change ellipsis to EllipsisType and maybe have a note somewhere that those using Python < 3.10 can use the equivalent type(...) or type(Ellipsis).
Potentially related to
- #589
- #229
- Dominant language
- Python
- Stars
- 281
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from data-apis/array-api
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Maintenance
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
All issues in data-apis/array-api
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100