From 03b2de655381a82592b7003d574e6f9d94c7fbb1 Mon Sep 17 00:00:00 2001 From: Sasha Lopoukhine Date: Fri, 14 Jul 2023 11:17:09 +0700 Subject: [PATCH] reqs: add typing-extension dependency (#1263) 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> --- requirements.txt | 1 + xdsl/interpreters/shaped_array.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index df29eac795..d8ebb01cfa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pip<24.0 immutabledict<2.2.6 +typing-extensions>=4.7,<5 diff --git a/xdsl/interpreters/shaped_array.py b/xdsl/interpreters/shaped_array.py index 9b082ee656..36a51d277b 100644 --- a/xdsl/interpreters/shaped_array.py +++ b/xdsl/interpreters/shaped_array.py @@ -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") @@ -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. """