Skip to content

Commit

Permalink
Changed import of TypeGuard to make it pre-3.10 suitable
Browse files Browse the repository at this point in the history
  • Loading branch information
krcb197 committed Dec 3, 2024
1 parent 3b02ac7 commit 5519e6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/peakrdl_python/lib/async_register_and_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
10 changes: 9 additions & 1 deletion src/peakrdl_python/lib/register_and_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down

0 comments on commit 5519e6d

Please sign in to comment.