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