Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy validation fails as of 0.35.0 #176

Open
lotus-kefir opened this issue Jan 20, 2025 · 3 comments · May be fixed by #177
Open

mypy validation fails as of 0.35.0 #176

lotus-kefir opened this issue Jan 20, 2025 · 3 comments · May be fixed by #177

Comments

@lotus-kefir
Copy link

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
@rnag
Copy link
Owner

rnag commented Jan 20, 2025

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 rnag linked a pull request Jan 20, 2025 that will close this issue
@lotus-kefir
Copy link
Author

lotus-kefir commented Jan 21, 2025

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!

@talawahtech
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants