dataclass-wizard icon indicating copy to clipboard operation
dataclass-wizard copied to clipboard

mypy validation fails as of 0.35.0

Open lotus-kefir opened this issue 11 months ago • 3 comments

Switching from v0.34.0 -> v0.35.0 starts raising this error:

mypy run-test: commands[1] | mypy --config-file tox.ini test_proj
.tox/mypy/lib/python3.9/site-packages/dataclass_wizard/wizard_mixins.pyi:20: error:
invalid syntax 
[syntax]
    type FileType = str | bytes | PathLike
          ^
Found 1 error in 1 file (errors prevented further checking)

I checked pip was on newest for both, didn't seem to make a difference.

Minimal reproduction:

test_proj/main.py

import dataclass_wizard

print('ok')

pyproject.toml

[project]
name = "test_proj"
requires-python = ">=3.9"
dynamic = ["version", "dependencies", "optional-dependencies"]

[tool.vulcan]
packages = ["test_proj"]
no-lock = true

[tool.vulcan.dependencies]
# Change between 34 & 35
dataclass-wizard = "==0.35.0"

[tool.vulcan.extras]
build_static_analysis = [
    "mypy~=1.14",
]

[tool.setuptools.dynamic.version]
file = "VERSION"

[tool.setuptools.packages.find]
include = ["test_proj"]

[build-system]
requires = [ "vulcan-py~=2.0" ]
build-backend = "vulcan.build_backend"

tox.ini

[tox]
requires = 
	tox < 4.0
	tox >= 3.22
envlist = mypy, flake8, wheel,test
isolated_build = True

[testenv]
recreate = true
basepython = python3.9
passenv = bamboo_*
platform = 
	linux: linux
allowlist_externals = 
	/bin/mkdir
; I use a different internal index_url + trusted_host, other than that no changes
install_command = pip install --no-compile --disable-pip-version-check {packages}

[testenv:mypy]
extras = build_static_analysis
commands = 
    pip install --upgrade pip
	mypy --config-file tox.ini test_proj

[mypy]
show_error_codes = True
pretty = True

Run with

python3.9 -m venv .venv; source .venv/bin/activate.fish; pip install --upgrade pip; 
pip install -e .
tox -e mypy

lotus-kefir avatar Jan 20 '25 11:01 lotus-kefir

Thank you for pointing this out! You’re correct that the type ... syntax is relatively new and only supported in more modern Python versions. While .pyi files are generally used for type hinting and are version-agnostic, it seems that type checkers like mypy may not fully support this syntax yet, or they might depend on the system Python version even when processing .pyi files.

To maintain compatibility, I’ll roll back the changes involving this syntax in the upcoming bugfix patch version. It should be a straightforward fix, and I’ll update the issue once the patch is released.

If you have any other concerns or suggestions, feel free to share. Thanks again for helping me catch this!

rnag avatar Jan 20 '25 18:01 rnag

Thank you for pointing this out! You’re correct that the type ... syntax is relatively new and only supported in more modern Python versions. While .pyi files are generally used for type hinting and are version-agnostic, it seems that type checkers like mypy may not fully support this syntax yet, or they might depend on the system Python version even when processing .pyi files.

To maintain compatibility, I’ll roll back the changes involving this syntax in the upcoming bugfix patch version. It should be a straightforward fix, and I’ll update the issue once the patch is released.

If you have any other concerns or suggestions, feel free to share. Thanks again for helping me catch this!

cool, thanks very much for the explanation + quick response!

lotus-kefir avatar Jan 21 '25 14:01 lotus-kefir

I hit the same error, but for a different file. I didn't see it in the 0.35.1 PR so I figured I should mention it.

/local/home/REDACTED/.cache/pre-commit/REDACTED/py_env-python3/lib/python3.9/site-packages/dataclass_wizard/v1/models.pyi:18:7: error:
invalid syntax  [syntax]
    type _STR_COLLECTION = str | Collection[str]
          ^
Found 1 error in 1 file (errors prevented further checking)

talawahtech avatar Jan 24 '25 22:01 talawahtech

Hey any update on fix here / when 0.35.1 will be released?

lcornelatti avatar Jul 08 '25 13:07 lcornelatti

@lcornelatti Apologies for the long delay – the changes are now live in v0.35.1. Thanks for your patience!

rnag avatar Jul 27 '25 21:07 rnag

Hey @rnag , this is actually not fixed yet, still breaking in a few other places, I made a PR myself to fix it, if you could review would be appreciated https://github.com/rnag/dataclass-wizard/pull/197

lcornelatti avatar Jul 28 '25 12:07 lcornelatti