Skip to content

Commit

Permalink
Restore compatibility with python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsbuwen committed Aug 17, 2023
1 parent 500d48c commit 4f8e0f7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ precision = 2
exclude_also = ["raise NotImplementedError"]

[tool.mypy]
python_version = "3.8"
files = "skillbridge"
pretty = true
show_error_context = true
Expand Down
42 changes: 19 additions & 23 deletions skillbridge/client/hints.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, NamedTuple, NewType, TypeAlias
from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, NewType, Tuple, Union

if TYPE_CHECKING: # pragma: no cover
from typing_extensions import Protocol
from typing_extensions import Protocol, TypeAlias
else:

class Protocol:
Expand All @@ -17,15 +17,14 @@ class Protocol:
'SkillComponent',
'SkillCode',
'Skill',
'Definition',
'Function',
'SkillTuple',
'SkillList',
'SupportsReprSkill',
]

Number = int | float
SkillComponent = int | str
Number = Union[int, float]
SkillComponent = Union[int, str]
SkillCode = NewType('SkillCode', str)


Expand All @@ -35,9 +34,6 @@ class Function(NamedTuple):
aliases: set[str]


Definition = list[Function]


class SupportsReprSkill(Protocol):
def __repr_skill__(self) -> SkillCode: # pragma: no cover
...
Expand All @@ -46,31 +42,31 @@ def __repr_skill__(self) -> SkillCode: # pragma: no cover
if TYPE_CHECKING: # pragma: no cover
from .var import Var

Skill: TypeAlias = (
Var
| SupportsReprSkill
| Number
| str
| bool
| None
| 'SkillList'
| 'SkillDict'
| 'SkillTuple'
)
Skill: TypeAlias = Union[
Var,
SupportsReprSkill,
Number,
str,
bool,
None,
'SkillList',
'SkillDict',
'SkillTuple',
]

else:
Skill: TypeAlias = Any
Skill = Any


class SkillList(list[Skill]):
class SkillList(List[Skill]):
pass


class SkillTuple(tuple[Skill, ...]):
class SkillTuple(Tuple[Skill, ...]):
__slots__ = ()


class SkillDict(dict[str, Skill]):
class SkillDict(Dict[str, Skill]):
pass


Expand Down
5 changes: 4 additions & 1 deletion skillbridge/client/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def _raise_error(message: str) -> NoReturn:

def _show_warning(message: str, result: Any) -> Any:
for i, line in enumerate(message.splitlines(keepends=False)):
warn_explicit(line.removeprefix("*WARNING*"), UserWarning, "Skill response", i)
message = line
if line.startswith("*WARNING*"):
message = message[9:]
warn_explicit(message, UserWarning, "Skill response", i)

return result

Expand Down
4 changes: 2 additions & 2 deletions skillbridge/client/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from inspect import signature
from logging import getLogger
from textwrap import dedent
from typing import Any, Callable, Iterable, NoReturn, cast
from typing import Any, Callable, Iterable, NoReturn, Union, cast

from .channel import Channel, DirectChannel, create_channel_class
from .functions import FunctionCollection, LiteralRemoteFunction
Expand All @@ -17,7 +17,7 @@

__all__ = ['Workspace', 'current_workspace']

WorkspaceId = str | int | None
WorkspaceId = Union[str, int, None]
_open_workspaces: dict[WorkspaceId, Workspace] = {}


Expand Down

0 comments on commit 4f8e0f7

Please sign in to comment.