From 390b5055c49708abb791728db1f63d5f74282ac4 Mon Sep 17 00:00:00 2001 From: Baptiste Fontaine Date: Wed, 27 Nov 2024 11:36:57 +0100 Subject: [PATCH] Fix typing for Python <3.11 --- magento/client.py | 4 ++-- magento/types.py | 8 +++++++- poetry.lock | 2 +- pyproject.toml | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/magento/client.py b/magento/client.py index cb9d74e..8cbd91d 100644 --- a/magento/client.py +++ b/magento/client.py @@ -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: @@ -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. diff --git a/magento/types.py b/magento/types.py index 822c6a1..f4eec5d 100644 --- a/magento/types.py +++ b/magento/types.py @@ -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', diff --git a/poetry.lock b/poetry.lock index 36b050d..c5f23e6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -916,4 +916,4 @@ docs = ["Sphinx", "sphinx-rtd-theme"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "bfcffa52ca2980f4f541790c1730d3ea053f6290a9a80b9bf1157c0a458d4a82" +content-hash = "333883097f89ccd261363260b9142ed7246c1edb8bd2a09b77802c89164e3fd7" diff --git a/pyproject.toml b/pyproject.toml index 03b6edd..a55388a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"