Skip to content

Commit 9acc769

Browse files
authored
Fix and update pre-commit tests (lovasoa#224)
* Fix pre-commit config The flake8 repo at gitlab was deleted. * Run pre-commit autoupdate (except flake8) We stick with flake8<6 since flake8==6.0.0 requires python>=3.8.1. * Fixes for mypy 0.991 - Fix for change of default config to no_implicit_optional=True (PEP 484 prohibits implicit optional). - Error type for incompatible imports changed from `misc` to `assignment`. * Use strategy.fail-fast=false for python test workflow When tests fail for one python version, we'd still like to see whether they pass for other python versions.
1 parent a6be7f0 commit 9acc769

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010

1111
runs-on: ubuntu-latest
1212
strategy:
13+
fail-fast: false
1314
matrix:
1415
python_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.9"]
1516

.pre-commit-config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/asottile/pyupgrade
3-
rev: v3.2.0
3+
rev: v3.2.3
44
hooks:
55
- id: pyupgrade
66
args: ["--py36-plus"]
@@ -9,13 +9,14 @@ repos:
99
hooks:
1010
- id: black
1111
language_version: python3
12-
- repo: https://gitlab.com/pycqa/flake8
12+
- repo: https://github.com/PyCQA/flake8
13+
# Flake8==6.0.0 requires python>=3.8.1
1314
rev: 5.0.4
1415
hooks:
1516
- id: flake8
1617
additional_dependencies: ['flake8-bugbear==22.10.27']
1718
- repo: https://github.com/pre-commit/mirrors-mypy
18-
rev: v0.982
19+
rev: v0.991
1920
hooks:
2021
- id: mypy
2122
additional_dependencies: [marshmallow-enum,typeguard,marshmallow]

marshmallow_dataclass/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def dataclass(
116116
# underscore. The presence of _cls is used to detect if this
117117
# decorator is being called with parameters or not.
118118
def dataclass(
119-
_cls: Type[_U] = None,
119+
_cls: Optional[Type[_U]] = None,
120120
*,
121121
repr: bool = True,
122122
eq: bool = True,
@@ -173,16 +173,16 @@ def add_schema(_cls: Type[_U]) -> Type[_U]:
173173

174174
@overload
175175
def add_schema(
176-
base_schema: Type[marshmallow.Schema] = None,
176+
base_schema: Optional[Type[marshmallow.Schema]] = None,
177177
) -> Callable[[Type[_U]], Type[_U]]:
178178
...
179179

180180

181181
@overload
182182
def add_schema(
183183
_cls: Type[_U],
184-
base_schema: Type[marshmallow.Schema] = None,
185-
cls_frame: types.FrameType = None,
184+
base_schema: Optional[Type[marshmallow.Schema]] = None,
185+
cls_frame: Optional[types.FrameType] = None,
186186
) -> Type[_U]:
187187
...
188188

@@ -224,7 +224,7 @@ def decorator(clazz: Type[_U]) -> Type[_U]:
224224
def class_schema(
225225
clazz: type,
226226
base_schema: Optional[Type[marshmallow.Schema]] = None,
227-
clazz_frame: types.FrameType = None,
227+
clazz_frame: Optional[types.FrameType] = None,
228228
) -> Type[marshmallow.Schema]:
229229
"""
230230
Convert a class to a marshmallow schema
@@ -363,7 +363,7 @@ def class_schema(
363363
def _internal_class_schema(
364364
clazz: type,
365365
base_schema: Optional[Type[marshmallow.Schema]] = None,
366-
clazz_frame: types.FrameType = None,
366+
clazz_frame: Optional[types.FrameType] = None,
367367
) -> Type[marshmallow.Schema]:
368368
_RECURSION_GUARD.seen_classes[clazz] = clazz.__name__
369369
try:
@@ -599,7 +599,7 @@ def _field_for_generic_type(
599599
def field_for_schema(
600600
typ: type,
601601
default=marshmallow.missing,
602-
metadata: Mapping[str, Any] = None,
602+
metadata: Optional[Mapping[str, Any]] = None,
603603
base_schema: Optional[Type[marshmallow.Schema]] = None,
604604
typ_frame: Optional[types.FrameType] = None,
605605
) -> marshmallow.fields.Field:
@@ -748,7 +748,7 @@ def _base_schema(
748748
# Remove `type: ignore` when mypy handles dynamic base classes
749749
# https://github.com/python/mypy/issues/2813
750750
class BaseSchema(base_schema or marshmallow.Schema): # type: ignore
751-
def load(self, data: Mapping, *, many: bool = None, **kwargs):
751+
def load(self, data: Mapping, *, many: Optional[bool] = None, **kwargs):
752752
all_loaded = super().load(data, many=many, **kwargs)
753753
many = self.many if many is None else bool(many)
754754
if many:

marshmallow_dataclass/lazy_class_attribute.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Callable
1+
from typing import Any, Callable, Optional
22

33

44
__all__ = ("lazy_class_attribute",)
@@ -13,7 +13,10 @@ class LazyClassAttribute:
1313
__slots__ = ("func", "name", "called", "forward_value")
1414

1515
def __init__(
16-
self, func: Callable[..., Any], name: str = None, forward_value: Any = None
16+
self,
17+
func: Callable[..., Any],
18+
name: Optional[str] = None,
19+
forward_value: Any = None,
1720
):
1821
self.func = func
1922
self.name = name

tests/test_class_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
try:
88
from typing import Final, Literal # type: ignore[attr-defined]
99
except ImportError:
10-
from typing_extensions import Final, Literal # type: ignore[misc]
10+
from typing_extensions import Final, Literal # type: ignore[assignment]
1111

1212
import dataclasses
1313
from marshmallow import Schema, ValidationError

tests/test_field_for_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
try:
99
from typing import Final, Literal # type: ignore[attr-defined]
1010
except ImportError:
11-
from typing_extensions import Final, Literal # type: ignore[misc]
11+
from typing_extensions import Final, Literal # type: ignore[assignment]
1212

1313
from marshmallow import fields, Schema, validate
1414

0 commit comments

Comments
 (0)