Skip to content

Commit

Permalink
reqs: add typing-extension dependency (#1263)
Browse files Browse the repository at this point in the history
Self is a very useful type to have available, introduced in 3.11. In
Python 3.10 a third-party module is required for the same functionality.
I reckon the extra dependency is worth it for the kind of thing we'd
like to express.

It seems to me like it's necessary to make it a required dependency as
core code should be able to use Self, so users of pip install should
inherit it as well. It's a bit annoying to have a dependency that's only
required for python 3.10 but it seems worth it to me.

---------

Co-authored-by: kingiler <68145845+kingiler@users.noreply.github.com>
  • Loading branch information
superlopuh and kingiler committed Jul 14, 2023
1 parent b7327f3 commit 03b2de6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pip<24.0
immutabledict<2.2.6
typing-extensions>=4.7,<5
5 changes: 3 additions & 2 deletions xdsl/interpreters/shaped_array.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import operator
from dataclasses import dataclass
from itertools import accumulate, product
from math import prod
from typing import Generic, Iterable, TypeAlias, TypeVar

from attr import dataclass
from typing_extensions import Self

_T = TypeVar("_T")

Expand Down Expand Up @@ -64,7 +65,7 @@ def indices(self) -> Iterable[tuple[int, ...]]:
"""
yield from product(*(range(dim) for dim in self.shape))

def transposed(self, dim0: int, dim1: int) -> ShapedArray[_T]:
def transposed(self, dim0: int, dim1: int) -> Self:
"""
Returns a new ShapedArray, with the dimensions `dim0` and `dim1` transposed.
"""
Expand Down

0 comments on commit 03b2de6

Please sign in to comment.