Skip to content

Commit

Permalink
Update for old pythons compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Gauvrit committed Jan 9, 2024
1 parent 6c50e5c commit 3714b52
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/blacksmith/domain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from .exceptions import ConfigurationError, UnregisteredClientException
from .model import AbstractCollectionParser, Request, Response


TRequest = TypeVar("TRequest", bound=Request)

Schemas = Tuple[TRequest, Optional[Type[Response]]]
Expand Down
2 changes: 1 addition & 1 deletion src/blacksmith/service/_async/route_proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict, Generic, List, Mapping, Optional, Tuple, Type, Union

try:
from types import UnionType
from types import UnionType # type: ignore
except ImportError: # coverage: ignore
# python 3.7 compat
UnionType = Union # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion src/blacksmith/service/_sync/route_proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict, Generic, List, Mapping, Optional, Tuple, Type, Union

try:
from types import UnionType
from types import UnionType # type: ignore
except ImportError: # coverage: ignore
# python 3.7 compat
UnionType = Union # type: ignore
Expand Down
16 changes: 15 additions & 1 deletion tests/unittests/_async/test_service_route_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,28 @@ def test_build_timeout() -> None:
[
pytest.param({"type": int, "expected": False}, id="int"),
pytest.param({"type": str, "expected": False}, id="str"),
pytest.param({"type": int | str, "expected": True}, id="int | str"),
pytest.param({"type": Union[int, str], "expected": True}, id="Union[int, str]"),
],
)
def test_is_union(params: Mapping[str, Any]):
assert is_union(params["type"]) is params["expected"]


try:

@pytest.mark.parametrize(
"params",
[
pytest.param({"type": int | str, "expected": True}, id="int | str"),
],
)
def test_is_union_py310(params: Mapping[str, Any]):
assert is_union(params["type"]) is params["expected"]

except TypeError:
...


class Foo(BaseModel):
typ: Literal["foo"]

Expand Down
1 change: 0 additions & 1 deletion tests/unittests/_sync/test_service_route_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def test_build_timeout() -> None:
[
pytest.param({"type": int, "expected": False}, id="int"),
pytest.param({"type": str, "expected": False}, id="str"),
pytest.param({"type": int | str, "expected": True}, id="int | str"),
pytest.param({"type": Union[int, str], "expected": True}, id="Union[int, str]"),
],
)
Expand Down
6 changes: 3 additions & 3 deletions tests/unittests/test_registry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Literal
from typing import Literal, Union

import pytest

Expand Down Expand Up @@ -131,7 +131,7 @@ class BarRequest(Request):
"v5",
path="/dummies/{name}",
contract={
"GET": (FooRequest | BarRequest, None),
"GET": (Union[FooRequest, BarRequest], None),
},
)

Expand All @@ -145,7 +145,7 @@ class BarRequest(Request):
assert api["dummies"].resource.contract is not None
assert api["dummies"].resource.path == "/dummies/{name}"
assert set(api["dummies"].resource.contract.keys()) == {"GET"}
assert api["dummies"].resource.contract["GET"][0] == FooRequest | BarRequest
assert api["dummies"].resource.contract["GET"][0] == Union[FooRequest, BarRequest]
assert api["dummies"].resource.contract["GET"][1] is None


Expand Down

0 comments on commit 3714b52

Please sign in to comment.