diff --git a/mashumaro/config.py b/mashumaro/config.py index e2a3df4d..90d658d3 100644 --- a/mashumaro/config.py +++ b/mashumaro/config.py @@ -1,15 +1,9 @@ -from typing import Any, Callable, Dict, List, Optional, Type, Union +from typing import Any, Callable, Dict, List, Literal, Optional, Type, Union -from mashumaro.core.const import PEP_586_COMPATIBLE, Sentinel +from mashumaro.core.const import Sentinel from mashumaro.dialect import Dialect from mashumaro.types import Discriminator, SerializationStrategy -if PEP_586_COMPATIBLE: - from typing import Literal # type: ignore -else: - from typing_extensions import Literal # type: ignore - - __all__ = [ "BaseConfig", "TO_DICT_ADD_BY_ALIAS_FLAG", diff --git a/mashumaro/core/const.py b/mashumaro/core/const.py index 06bf25c0..4353326b 100644 --- a/mashumaro/core/const.py +++ b/mashumaro/core/const.py @@ -5,12 +5,10 @@ "PY_38", "PY_39", "PY_310", - "PY_38_MIN", "PY_39_MIN", "PY_310_MIN", "PY_311_MIN", "PEP_585_COMPATIBLE", - "PEP_586_COMPATIBLE", "Sentinel", ] @@ -24,10 +22,8 @@ PY_311_MIN = PY_311 or PY_312_MIN PY_310_MIN = PY_310 or PY_311_MIN PY_39_MIN = PY_39 or PY_310_MIN -PY_38_MIN = PY_38 or PY_39_MIN PEP_585_COMPATIBLE = PY_39_MIN # Type Hinting Generics In Standard Collections -PEP_586_COMPATIBLE = PY_38_MIN # Literal Types class Sentinel(enum.Enum): diff --git a/mashumaro/core/meta/helpers.py b/mashumaro/core/meta/helpers.py index b1ce168e..cb22df7d 100644 --- a/mashumaro/core/meta/helpers.py +++ b/mashumaro/core/meta/helpers.py @@ -32,7 +32,6 @@ from mashumaro.core.const import ( PEP_585_COMPATIBLE, PY_38, - PY_38_MIN, PY_39, PY_39_MIN, PY_310_MIN, @@ -424,10 +423,7 @@ def is_final(typ: Type) -> bool: def is_init_var(typ: Type) -> bool: - if PY_38_MIN: - return isinstance(typ, dataclasses.InitVar) - else: - raise NotImplementedError + return isinstance(typ, dataclasses.InitVar) def get_class_that_defines_method( diff --git a/tests/test_meta.py b/tests/test_meta.py index 6f189a70..fd557126 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -1,19 +1,14 @@ import collections import collections.abc import typing -from dataclasses import dataclass +from dataclasses import InitVar, dataclass from datetime import datetime import pytest import typing_extensions from mashumaro import DataClassDictMixin -from mashumaro.core.const import ( - PEP_585_COMPATIBLE, - PY_38, - PY_38_MIN, - PY_310_MIN, -) +from mashumaro.core.const import PEP_585_COMPATIBLE, PY_38, PY_310_MIN from mashumaro.core.meta.code.builder import CodeBuilder # noinspection PyProtectedMember @@ -88,10 +83,9 @@ def test_is_generic_unsupported_python(mocker): is_generic(int) -def test_is_init_var_unsupported_python(mocker): - mocker.patch("mashumaro.core.meta.helpers.PY_38_MIN", False) - with pytest.raises(NotImplementedError): - is_init_var(int) +def test_is_init_var(): + assert is_init_var(InitVar[int]) + assert not is_init_var(int) def test_is_literal_unsupported_python(mocker): @@ -542,12 +536,8 @@ def test_get_literal_values(): def test_type_name_literal(): - if PY_38_MIN: - module = typing - else: - module = typing_extensions assert type_name( - getattr(module, "Literal")[ + getattr(typing, "Literal")[ 1, "a", b"\x00", @@ -564,7 +554,7 @@ def test_type_name_literal(): typing_extensions.Literal[typing_extensions.Literal["b", "c"]], ] ) == ( - f"{module.__name__}.Literal[1, 'a', b'\\x00', True, False, None, " + f"typing.Literal[1, 'a', b'\\x00', True, False, None, " "tests.entities.MyEnum.a, tests.entities.MyStrEnum.a, " "tests.entities.MyNativeStrEnum.a, tests.entities.MyIntEnum.a, " "tests.entities.MyFlag.a, tests.entities.MyIntFlag.a, 2, 3, 'b', 'c']"