From 5519e6d92621da4fe284b344b85f2e9536323bbb Mon Sep 17 00:00:00 2001 From: krcb197 <34693973+krcb197@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:18:22 +0000 Subject: [PATCH] Changed import of TypeGuard to make it pre-3.10 suitable --- src/peakrdl_python/lib/async_register_and_field.py | 10 +++++++++- src/peakrdl_python/lib/register_and_field.py | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/peakrdl_python/lib/async_register_and_field.py b/src/peakrdl_python/lib/async_register_and_field.py index 794571b..be6fe58 100644 --- a/src/peakrdl_python/lib/async_register_and_field.py +++ b/src/peakrdl_python/lib/async_register_and_field.py @@ -20,7 +20,7 @@ asynchronous registers and fields """ from enum import Enum -from typing import List, Union, Iterator, Tuple, Optional, Dict, TypeVar, cast, TypeGuard +from typing import List, Union, Iterator, Tuple, Optional, Dict, TypeVar, cast from typing import AsyncGenerator from abc import ABC, abstractmethod from contextlib import asynccontextmanager @@ -47,6 +47,14 @@ from typing_extensions import Self # pylint: enable=duplicate-code +# pylint: disable=duplicate-code +if sys.version_info >= (3, 10): + # type guarding was introduced in python 3.10 + from typing import TypeGuard +else: + from typing_extensions import TypeGuard +# pylint: enable=duplicate-code + # pylint: disable=redefined-slots-in-subclass,too-many-lines diff --git a/src/peakrdl_python/lib/register_and_field.py b/src/peakrdl_python/lib/register_and_field.py index eb68cbb..1a092b9 100644 --- a/src/peakrdl_python/lib/register_and_field.py +++ b/src/peakrdl_python/lib/register_and_field.py @@ -20,7 +20,7 @@ registers and fields """ from enum import Enum -from typing import List, Union, Iterator, Tuple, cast, Optional, Dict, TypeVar, TypeGuard +from typing import List, Union, Iterator, Tuple, cast, Optional, Dict, TypeVar from typing import Generator from abc import ABC, abstractmethod from contextlib import contextmanager @@ -47,6 +47,14 @@ from typing_extensions import Self # pylint: enable=duplicate-code +# pylint: disable=duplicate-code +if sys.version_info >= (3, 10): + # type guarding was introduced in python 3.10 + from typing import TypeGuard +else: + from typing_extensions import TypeGuard +# pylint: enable=duplicate-code + # pylint: disable=redefined-slots-in-subclass,too-many-lines