From e24a87ed8d1fb1a50dcd29a0ae1f4767418dfd50 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Sun, 2 Jun 2024 13:38:56 +0000 Subject: [PATCH] [BE][Ez]: Apply PYI059 - Generic always come last (#127685) Generic baseclass should always be last or unexpected issues can occur, especially in non-stub files (such as with MRO). Applies autofixes from the preview PYI059 rule to fix the issues in the codebase. Pull Request resolved: https://github.com/pytorch/pytorch/pull/127685 Approved by: https://github.com/ezyang --- test/test_datapipe.py | 2 +- torch/_inductor/utils.py | 2 +- torch/onnx/_internal/registration.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_datapipe.py b/test/test_datapipe.py index b6be7eb76b9..37cf896eda2 100644 --- a/test/test_datapipe.py +++ b/test/test_datapipe.py @@ -2423,7 +2423,7 @@ class TestFunctionalMapDataPipe(TestCase): _generic_namedtuple_allowed = sys.version_info >= (3, 7) and sys.version_info < (3, 9) if _generic_namedtuple_allowed: - class InvalidData(Generic[T_co], NamedTuple): + class InvalidData(NamedTuple, Generic[T_co]): name: str data: T_co diff --git a/torch/_inductor/utils.py b/torch/_inductor/utils.py index 7a96630ef21..0915a8330c3 100644 --- a/torch/_inductor/utils.py +++ b/torch/_inductor/utils.py @@ -390,7 +390,7 @@ P = ParamSpec("P") RV = TypeVar("RV", covariant=True) -class CachedMethod(Generic[P, RV], Protocol): +class CachedMethod(Protocol, Generic[P, RV]): @staticmethod def clear_cache(self) -> None: ... diff --git a/torch/onnx/_internal/registration.py b/torch/onnx/_internal/registration.py index 017a2fb7dad..3b2e68e1e40 100644 --- a/torch/onnx/_internal/registration.py +++ b/torch/onnx/_internal/registration.py @@ -61,7 +61,7 @@ _K = TypeVar("_K") _V = TypeVar("_V") -class OverrideDict(Generic[_K, _V], Collection[_K]): +class OverrideDict(Collection[_K], Generic[_K, _V]): """A dictionary that merges built-in and custom symbolic functions. It supports overriding and un-overriding built-in symbolic functions with custom