Skip to content

Commit

Permalink
Refresh code with Python 3.8 deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatal1ty committed Nov 13, 2024
1 parent 3670e38 commit 5aecf9f
Show file tree
Hide file tree
Showing 40 changed files with 374 additions and 586 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Remember, everyone starts somewhere, and we're here to support you on your journ
#### Setting up your Development Environment

Before getting started, you will need to have already installed:
* [python](https://www.python.org) (3.8+ only)
* [python](https://www.python.org) (3.9+ only)
* [git](https://git-scm.com)
* [just](https://github.com/casey/just)

Expand Down
6 changes: 3 additions & 3 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.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Use pip to install:
$ pip install mashumaro
```

The current version of `mashumaro` supports Python versions 3.8 — 3.13.
The current version of `mashumaro` supports Python versions 3.9 — 3.13.


It's not recommended to use any version of Python that has reached its
Expand All @@ -155,6 +155,7 @@ of Python.

| Python Version | Last Version of mashumaro | Python EOL |
|----------------|--------------------------------------------------------------------|------------|
| 3.8 | [3.14](https://github.com/Fatal1ty/mashumaro/releases/tag/v3.14) | 2024-10-07 |
| 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 |

Expand Down
3 changes: 2 additions & 1 deletion mashumaro/codecs/_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from typing import Any, Callable, Optional, Type
from collections.abc import Callable
from typing import Any, Optional, Type

from mashumaro.core.meta.code.builder import CodeBuilder
from mashumaro.core.meta.helpers import is_optional, is_type_var_any
Expand Down
2 changes: 1 addition & 1 deletion mashumaro/codecs/basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
from typing import (
Any,
Callable,
Generic,
Optional,
Type,
Expand Down
2 changes: 1 addition & 1 deletion mashumaro/codecs/json.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from collections.abc import Callable
from typing import (
Any,
Callable,
Generic,
Optional,
Type,
Expand Down
2 changes: 1 addition & 1 deletion mashumaro/codecs/msgpack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
from typing import (
Any,
Callable,
Generic,
Optional,
Type,
Expand Down
2 changes: 1 addition & 1 deletion mashumaro/codecs/yaml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
from typing import (
Any,
Callable,
Generic,
Optional,
Type,
Expand Down
21 changes: 6 additions & 15 deletions mashumaro/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
from typing import (
Any,
Callable,
Dict,
List,
Literal,
Optional,
Type,
TypedDict,
Union,
)
from collections.abc import Callable
from typing import Any, Literal, Optional, Type, TypedDict, Union

from mashumaro.core.const import Sentinel
from mashumaro.dialect import Dialect
Expand Down Expand Up @@ -50,9 +41,9 @@ class SerializationStrategyDict(TypedDict, total=False):

class BaseConfig:
debug: bool = False
code_generation_options: List[CodeGenerationOption] = []
serialization_strategy: Dict[Any, SerializationStrategyValueType] = {}
aliases: Dict[str, str] = {}
code_generation_options: list[CodeGenerationOption] = []
serialization_strategy: dict[Any, SerializationStrategyValueType] = {}
aliases: dict[str, str] = {}
serialize_by_alias: Union[bool, Literal[Sentinel.MISSING]] = (
Sentinel.MISSING
)
Expand All @@ -64,7 +55,7 @@ class BaseConfig:
omit_none: Union[bool, Literal[Sentinel.MISSING]] = Sentinel.MISSING
omit_default: Union[bool, Literal[Sentinel.MISSING]] = Sentinel.MISSING
orjson_options: Optional[int] = 0
json_schema: Dict[str, Any] = {}
json_schema: dict[str, Any] = {}
discriminator: Optional[Discriminator] = None
lazy_compilation: bool = False
sort_keys: bool = False
Expand Down
7 changes: 0 additions & 7 deletions mashumaro/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
import sys

__all__ = [
"PY_38",
"PY_39",
"PY_310",
"PY_39_MIN",
"PY_310_MIN",
"PY_311_MIN",
"PY_312_MIN",
"PY_313_MIN",
"PEP_585_COMPATIBLE",
"Sentinel",
]


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
PY_311 = sys.version_info.major == 3 and sys.version_info.minor == 11
Expand All @@ -25,9 +21,6 @@
PY_312_MIN = PY_312 or PY_313_MIN
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

PEP_585_COMPATIBLE = PY_39_MIN # Type Hinting Generics In Standard Collections


class Sentinel(enum.Enum):
Expand Down
30 changes: 14 additions & 16 deletions mashumaro/core/meta/code/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,18 @@ def __init__(
format_name: str = "dict",
decoder: typing.Optional[typing.Any] = None,
encoder: typing.Optional[typing.Any] = None,
encoder_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None,
encoder_kwargs: typing.Optional[dict[str, typing.Any]] = None,
default_dialect: typing.Optional[typing.Type[Dialect]] = None,
attrs: typing.Any = None,
attrs_registry: typing.Optional[
typing.Dict[typing.Any, typing.Any]
] = None,
attrs_registry: typing.Optional[dict[typing.Any, typing.Any]] = None,
):
self.cls = cls
self.lines: CodeLines = CodeLines()
self.globals: typing.Dict[str, typing.Any] = {}
self.resolved_type_params: typing.Dict[
typing.Type, typing.Dict[typing.Type, typing.Type]
self.globals: dict[str, typing.Any] = {}
self.resolved_type_params: dict[
typing.Type, dict[typing.Type, typing.Type]
] = {}
self.field_classes: typing.Dict = {}
self.field_classes: dict = {}
self.initial_type_args = type_args
if dialect is not None and not is_dialect_subclass(dialect):
raise BadDialect(
Expand Down Expand Up @@ -168,7 +166,7 @@ def namespace(self) -> typing.Mapping[typing.Any, typing.Any]:
return self.cls.__dict__

@property
def annotations(self) -> typing.Dict[str, typing.Any]:
def annotations(self) -> dict[str, typing.Any]:
return self.namespace.get("__annotations__", {})

@property
Expand All @@ -177,7 +175,7 @@ def is_nailed(self) -> bool:

def __get_field_types(
self, recursive: bool = True, include_extras: bool = False
) -> typing.Dict[str, typing.Any]:
) -> dict[str, typing.Any]:
fields = {}
try:
field_type_hints = typing_extensions.get_type_hints(
Expand Down Expand Up @@ -211,20 +209,20 @@ def get_real_type(

def get_field_resolved_type_params(
self, field_name: str
) -> typing.Dict[typing.Type, typing.Type]:
) -> dict[typing.Type, typing.Type]:
cls = self._get_field_class(field_name)
return self.resolved_type_params[cls]

def get_field_types(
self, include_extras: bool = False
) -> typing.Dict[str, typing.Any]:
) -> dict[str, typing.Any]:
return self.__get_field_types(include_extras=include_extras)

def get_type_name_identifier(
self,
typ: typing.Optional[typing.Type],
resolved_type_params: typing.Optional[
typing.Dict[typing.Type, typing.Type]
dict[typing.Type, typing.Type]
] = None,
) -> str:
field_type = type_name(typ, resolved_type_params=resolved_type_params)
Expand All @@ -237,7 +235,7 @@ def get_type_name_identifier(

@property
@lru_cache()
def dataclass_fields(self) -> typing.Dict[str, Field]:
def dataclass_fields(self) -> dict[str, Field]:
d = {}
for ancestor in self.cls.__mro__[-1:0:-1]:
if is_dataclass(ancestor):
Expand All @@ -256,7 +254,7 @@ def dataclass_fields(self) -> typing.Dict[str, Field]:
return d

@property
def metadatas(self) -> typing.Dict[str, typing.Mapping[str, typing.Any]]:
def metadatas(self) -> dict[str, typing.Mapping[str, typing.Any]]:
return {
name: field.metadata
for name, field in self.dataclass_fields.items()
Expand Down Expand Up @@ -1093,7 +1091,7 @@ def _add_pack_method_with_dialect_lines(self, method_name: str) -> None:

def _get_encoder_kwargs(
self, cls: typing.Optional[typing.Type] = None
) -> typing.Dict[str, typing.Any]:
) -> dict[str, typing.Any]:
result = {}
for encoder_param, value in self.encoder_kwargs.items():
packer_param = value[0]
Expand Down
5 changes: 3 additions & 2 deletions mashumaro/core/meta/code/lines.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from collections.abc import Generator
from contextlib import contextmanager
from typing import Generator, List, Optional
from typing import Optional

__all__ = ["CodeLines"]


class CodeLines:
def __init__(self) -> None:
self._lines: List[str] = []
self._lines: list[str] = []
self._current_indent: str = ""

def append(self, line: str) -> None:
Expand Down
Loading

0 comments on commit 5aecf9f

Please sign in to comment.