Skip to content

Commit

Permalink
Merge pull request #149 from Fatal1ty/drop-python37
Browse files Browse the repository at this point in the history
Drop support for Python 3.7
  • Loading branch information
Fatal1ty authored Aug 24, 2023
2 parents 76a79cd + 9514fbf commit b1eb33f
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 60 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -41,7 +41,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -68,7 +68,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: 3.11
- name: Install dependencies
run: pip install coveralls
- name: Finish coveralls
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,21 @@ Use pip to install:
$ pip install mashumaro
```

The current version of `mashumaro` supports Python versions 3.7 - 3.11.
The latest version of `mashumaro` that can be installed on Python 3.6 is 3.1.1.
The current version of `mashumaro` supports Python versions 3.8 - 3.11.


It's not recommended to use any version of Python that has reached its
[end of life](https://devguide.python.org/versions/) and is no longer receiving
security updates or bug fixes from the Python development team.
For convenience, there is a table below that outlines the
latest version of `mashumaro` that can be installed on unmaintained versions
of Python.

| Python Version | Latest Version of mashumaro | Python EOL |
|----------------|--------------------------------------------------------------------|------------|
| 3.7 | [3.9.1](https://github.com/Fatal1ty/mashumaro/releases/tag/v3.9.1) | 2023-06-27 |
| 3.6 | [3.1.1](https://github.com/Fatal1ty/mashumaro/releases/tag/v3.1.1) | 2021-12-23 |


Changelog
--------------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions mashumaro/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import sys

__all__ = [
"PY_37",
"PY_38",
"PY_39",
"PY_310",
"PY_37_MIN",
"PY_38_MIN",
"PY_39_MIN",
"PY_310_MIN",
Expand All @@ -17,7 +15,6 @@
]


PY_37 = sys.version_info.major == 3 and sys.version_info.minor == 7
PY_38 = sys.version_info.major == 3 and sys.version_info.minor == 8
PY_39 = sys.version_info.major == 3 and sys.version_info.minor == 9
PY_310 = sys.version_info.major == 3 and sys.version_info.minor == 10
Expand All @@ -28,7 +25,6 @@
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
PY_37_MIN = PY_37 or PY_38_MIN

PEP_585_COMPATIBLE = PY_39_MIN # Type Hinting Generics In Standard Collections
PEP_586_COMPATIBLE = PY_38_MIN # Literal Types
Expand Down
9 changes: 3 additions & 6 deletions mashumaro/core/meta/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

from mashumaro.core.const import (
PEP_585_COMPATIBLE,
PY_37,
PY_38,
PY_38_MIN,
PY_39,
Expand Down Expand Up @@ -291,7 +290,7 @@ def is_generic(typ: Type) -> bool:
with suppress(Exception):
if hasattr(typ, "__class_getitem__"):
return True
if PY_37 or PY_38:
if PY_38:
# noinspection PyProtectedMember
# noinspection PyUnresolvedReferences
return issubclass(typ.__class__, typing._GenericAlias) # type: ignore
Expand Down Expand Up @@ -376,7 +375,7 @@ def get_type_annotations(typ: Type) -> Sequence[Any]:


def is_literal(typ: Type) -> bool:
if PY_37 or PY_38 or PY_39:
if PY_38 or PY_39:
with suppress(AttributeError):
return is_generic(typ) and get_generic_name(typ, True) == "Literal"
elif PY_310_MIN:
Expand Down Expand Up @@ -423,9 +422,7 @@ def is_final(typ: Type) -> bool:


def is_init_var(typ: Type) -> bool:
if PY_37:
return get_type_origin(typ) is dataclasses.InitVar
elif PY_38_MIN:
if PY_38_MIN:
return isinstance(typ, dataclasses.InitVar)
else:
raise NotImplementedError
Expand Down
7 changes: 1 addition & 6 deletions mashumaro/core/meta/types/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections.abc
import uuid
from dataclasses import dataclass, field, is_dataclass, replace
from functools import cached_property
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -14,12 +15,6 @@
TypeVar,
)

try:
from functools import cached_property # type: ignore
except ImportError:
# for python 3.7
cached_property = property # type: ignore

from typing_extensions import ParamSpec, TypeAlias

from mashumaro.core.const import PEP_585_COMPATIBLE
Expand Down
4 changes: 1 addition & 3 deletions mashumaro/core/meta/types/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from fractions import Fraction
from typing import Any, Callable, List, Optional, Tuple, Type, Union

import typing_extensions

from mashumaro.core.const import PY_39_MIN, PY_311_MIN
from mashumaro.core.meta.code.lines import CodeLines
from mashumaro.core.meta.helpers import (
Expand Down Expand Up @@ -679,7 +677,7 @@ def inner_expr(
f"for key, value in m.items()}} "
f"for m in {spec.expression}.maps]"
)
elif ensure_generic_mapping(spec, args, typing_extensions.OrderedDict):
elif ensure_generic_mapping(spec, args, typing.OrderedDict):
return (
f'{{{inner_expr(0, "key")}: {inner_expr(1)} '
f"for key, value in {spec.expression}.items()}}"
Expand Down
4 changes: 1 addition & 3 deletions mashumaro/core/meta/types/unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from fractions import Fraction
from typing import Any, Callable, Iterable, List, Optional, Tuple, Type, Union

import typing_extensions

from mashumaro.core.const import PY_39_MIN, PY_311_MIN
from mashumaro.core.helpers import parse_timezone
from mashumaro.core.meta.code.lines import CodeLines
Expand Down Expand Up @@ -1079,7 +1077,7 @@ def inner_expr(
f'collections.ChainMap(*[{{{inner_expr(0, "key")}:{inner_expr(1)} '
f"for key, value in m.items()}} for m in {spec.expression}])"
)
elif ensure_generic_mapping(spec, args, typing_extensions.OrderedDict):
elif ensure_generic_mapping(spec, args, typing.OrderedDict):
spec.builder.ensure_module_imported(collections)
return (
f'collections.OrderedDict({{{inner_expr(0, "key")}: '
Expand Down
18 changes: 6 additions & 12 deletions mashumaro/jsonschema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from decimal import Decimal
from enum import Enum
from fractions import Fraction
from functools import cached_property
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -108,19 +109,12 @@ class Instance:
origin_type: Type = field(init=False)
annotations: List[Annotation] = field(init=False, default_factory=list)

__metadata: Optional[Dict[str, Any]] = field(init=False, default=None)

@property
# TODO: switch to cached_property after dropping python 3.7 support
@cached_property
def metadata(self) -> Dict[str, Any]:
if self.__metadata is None:
if self.name and self.__owner_builder:
self.__metadata = dict(
**self.__owner_builder.metadatas.get(self.name, {})
)
else:
self.__metadata = {}
return self.__metadata
if self.name and self.__owner_builder:
return dict(**self.__owner_builder.metadatas.get(self.name, {}))
else:
return {}

@property
def _self_builder(self) -> CodeBuilder:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ ensure_newline_before_comments = true

[tool.black]
line-length = 79
target-version = ['py37', 'py38', 'py39']
target-version = ['py38', 'py39', 'py310', 'py311']
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand All @@ -26,7 +25,7 @@
url="https://github.com/Fatal1ty/mashumaro",
packages=find_packages(include=("mashumaro", "mashumaro.*")),
package_data={"mashumaro": ["py.typed", "mixins/orjson.pyi"]},
python_requires=">=3.7",
python_requires=">=3.8",
install_requires=[
"typing_extensions>=4.1.0",
],
Expand Down
5 changes: 3 additions & 2 deletions tests/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@
MutableSet,
NewType,
Optional,
OrderedDict,
Sequence,
Set,
Tuple,
)

import pytest
from typing_extensions import Final, OrderedDict
from typing_extensions import Final

from mashumaro import DataClassDictMixin
from mashumaro.config import BaseConfig
from mashumaro.core.const import PEP_585_COMPATIBLE, PY_39_MIN, PY_311_MIN
from mashumaro.core.const import PEP_585_COMPATIBLE, PY_39_MIN
from mashumaro.exceptions import (
InvalidFieldValue,
MissingField,
Expand Down
9 changes: 2 additions & 7 deletions tests/test_jsonschema/test_jsonschema_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,15 @@
Mapping,
MutableMapping,
Optional,
OrderedDict,
Sequence,
Tuple,
Union,
)
from uuid import UUID

import pytest
from typing_extensions import (
Annotated,
Literal,
OrderedDict,
TypeVarTuple,
Unpack,
)
from typing_extensions import Annotated, Literal, TypeVarTuple, Unpack

from mashumaro.config import BaseConfig
from mashumaro.core.const import PEP_585_COMPATIBLE, PY_39_MIN
Expand Down
12 changes: 4 additions & 8 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from mashumaro import DataClassDictMixin
from mashumaro.core.const import (
PEP_585_COMPATIBLE,
PY_37,
PY_38,
PY_38_MIN,
PY_310_MIN,
Expand Down Expand Up @@ -83,22 +82,19 @@


def test_is_generic_unsupported_python(mocker):
mocker.patch("mashumaro.core.meta.helpers.PY_37", False)
mocker.patch("mashumaro.core.meta.helpers.PY_38", False)
mocker.patch("mashumaro.core.meta.helpers.PY_39_MIN", False)
with pytest.raises(NotImplementedError):
is_generic(int)


def test_is_init_var_unsupported_python(mocker):
mocker.patch("mashumaro.core.meta.helpers.PY_37", False)
mocker.patch("mashumaro.core.meta.helpers.PY_38_MIN", False)
with pytest.raises(NotImplementedError):
is_init_var(int)


def test_is_literal_unsupported_python(mocker):
mocker.patch("mashumaro.core.meta.helpers.PY_37", False)
mocker.patch("mashumaro.core.meta.helpers.PY_38", False)
mocker.patch("mashumaro.core.meta.helpers.PY_39", False)
mocker.patch("mashumaro.core.meta.helpers.PY_310_MIN", False)
Expand Down Expand Up @@ -181,8 +177,8 @@ def test_is_type_var_any():
assert not is_type_var_any(TMyDataClass)


@pytest.mark.skipif(not (PY_37 or PY_38), reason="requires python 3.7..3.8")
def test_is_type_var_any_list_37_38():
@pytest.mark.skipif(not PY_38, reason="requires python 3.8")
def test_is_type_var_any_list_38():
# noinspection PyProtectedMember
# noinspection PyUnresolvedReferences
assert is_type_var_any(typing.List.__args__[0])
Expand Down Expand Up @@ -215,7 +211,7 @@ def test_type_name():
== "typing.Union[int, typing.Any]"
)
assert (
type_name(typing_extensions.OrderedDict[int, int])
type_name(typing.OrderedDict[int, int])
== "typing.OrderedDict[int, int]"
)
assert (
Expand Down Expand Up @@ -325,7 +321,7 @@ def test_type_name_short():
== "Union[int, Any]"
)
assert (
type_name(typing_extensions.OrderedDict[int, int], short=True)
type_name(typing.OrderedDict[int, int], short=True)
== "OrderedDict[int, int]"
)
assert (
Expand Down

0 comments on commit b1eb33f

Please sign in to comment.