Skip to content

Commit

Permalink
Fix typing for Python <3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
bfontaine committed Nov 27, 2024
1 parent 2db827c commit 390b505
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions magento/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ def get_source_items(self, source_code: Optional[str] = None, sku: Optional[str]

return self.get_paginated("/V1/inventory/source-items", query=query, limit=limit, **kwargs)

def save_source_items(self, source_items: Sequence[SourceItem | SourceItemIn], **kwargs):
def save_source_items(self, source_items: Sequence[Union[SourceItem, SourceItemIn]], **kwargs):
"""Save a sequence of source-items. Return None if the sequence is empty.
:param source_items:
Expand All @@ -1173,7 +1173,7 @@ def save_source_items(self, source_items: Sequence[SourceItem | SourceItemIn], *
return None
return self.post_json_api("/V1/inventory/source-items", json={"sourceItems": source_items}, **kwargs)

def delete_source_items(self, source_items: Iterable[SourceItem | SourceItemIn], **kwargs):
def delete_source_items(self, source_items: Iterable[Union[SourceItem, SourceItemIn]], **kwargs):
"""Delete a sequence of source-items. Only the SKU and the source_code are used.
Note: Magento returns an error if this is called with empty source_items.
Expand Down
8 changes: 7 additions & 1 deletion magento/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from typing import Union, TypedDict, NotRequired
import sys
from typing import Union, TypedDict

from api_session import JSONDict

if sys.version_info >= (3, 11):
from typing import NotRequired
else:
from typing_extensions import NotRequired

__all__ = (
'Category',
'Customer',
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ api-session = "^1.4.2"
# https://github.com/jacopok/mlgw_bns/commit/50e82ad2e218873d1b3a8732b6cbeb5f692dd14c
Sphinx = { version = "^4.4.0", optional = true }
sphinx-rtd-theme = { version = "^1.0.0", optional = true }
typing-extensions = { version = "*", python = "<3.11" }

[tool.poetry.group.dev.dependencies]
mypy = "^1"
Expand Down

0 comments on commit 390b505

Please # to comment.