Skip to content

Commit db73714

Browse files
authored
Fix use of typing.NewType in Python 3.10 (lovasoa#180)
* Fix use of typing.NewType in Python 3.10 https://docs.python.org/3.10/library/typing.html#typing.NewType "Changed in version 3.10: NewType is now a class rather than a function." * Add Python 3.10 to GitHub workflow test matrix Note the use of strings: otherwise YAML thinks we want to test Python 3.1 * Pin types-dataclasses version for Python 3.6 It looks broken for Python 3.6 due to python/typeshed@a40d79a
1 parent 84542a5 commit db73714

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python_version: [3.6, 3.7, 3.8, 3.9, pypy3]
14+
python_version: ["3.6", "3.7", "3.8", "3.9", "3.10", "pypy3"]
1515

1616
steps:
1717
- uses: actions/checkout@v2

marshmallow_dataclass/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,10 @@ def field_for_schema(
595595
if generic_field:
596596
return generic_field
597597

598-
# typing.NewType returns a function with a __supertype__ attribute
599-
newtype_supertype = getattr(typ, "__supertype__", None)
600-
if newtype_supertype and inspect.isfunction(typ):
598+
# typing.NewType returns a function (in python <= 3.9) or a class (python >= 3.10) with a
599+
# __supertype__ attribute
600+
if typing_inspect.is_new_type(typ):
601+
newtype_supertype = getattr(typ, "__supertype__", None)
601602
return _field_by_supertype(
602603
typ=typ,
603604
default=default,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
EXTRAS_REQUIRE = {
1919
"enum": ["marshmallow-enum"],
2020
"union": ["typeguard"],
21-
':python_version == "3.6"': ["dataclasses", "types-dataclasses"],
21+
':python_version == "3.6"': ["dataclasses", "types-dataclasses<0.6.4"],
2222
"lint": ["pre-commit~=1.18"],
2323
"docs": ["sphinx"],
2424
"tests": [

0 commit comments

Comments
 (0)