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

Typeguard fails with 8.7.0 #272

Closed
epenet opened this issue Jun 28, 2024 · 3 comments · Fixed by #273
Closed

Typeguard fails with 8.7.0 #272

epenet opened this issue Jun 28, 2024 · 3 comments · Fixed by #273

Comments

@epenet
Copy link
Contributor

epenet commented Jun 28, 2024

It worked fine with 8.6.1
See hacf-fr/renault-api#1234

<frozen importlib._bootstrap>:935: in _load_unlocked
    ???
.nox/typeguard-3-12/lib/python3.12/site-packages/typeguard/_importhook.py:98: in exec_module
    super().exec_module(module)
.nox/typeguard-3-12/lib/python3.12/site-packages/renault_api/kamereon/models.py:15: in <module>
    from . import helpers
<frozen importlib._bootstrap>:1360: in _find_and_load
    ???
<frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:935: in _load_unlocked
    ???
.nox/typeguard-3-12/lib/python3.12/site-packages/typeguard/_importhook.py:98: in exec_module
    super().exec_module(module)
<frozen importlib._bootstrap_external>:991: in exec_module
    ???
<frozen importlib._bootstrap_external>:1129: in get_code
    ???
.nox/typeguard-3-12/lib/python3.12/site-packages/typeguard/_importhook.py:87: in source_to_code
    return _call_with_frames_removed(
.nox/typeguard-3-12/lib/python3.12/site-packages/typeguard/_importhook.py:47: in _call_with_frames_removed
    return f(*args, **kwargs)
E     File "/home/runner/work/renault-api/renault-api/.nox/typeguard-3-12/lib/python3.12/site-packages/renault_api/kamereon/helpers.py", line 3
E       from __future__ import annotations
E       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   SyntaxError: from __future__ imports must occur at the beginning of the file
@dairiki
Copy link
Collaborator

dairiki commented Jun 28, 2024

My guess is that this is more of a typeguard vs renault-api issue.

Previous to marshmallow_dataclass 8.7.0, typeguard was pinned to < 3. 8.7.0 relaxes that pin to allow for typeguard 4.x. (#250, #260)
The new behavior appears to be caused by the switch to typeguard 4.

From the traceback, this appears to have something to do with the use of typeguards import hook. In your case, the import hook appears to be installed through the use of the typeguard's pytest plugin.

@epenet
Copy link
Contributor Author

epenet commented Jun 28, 2024

OK - I'm making progress, but I am still confused.
It seems that the CI with marshmallow_dataclass 8.6.1, typeguard gets installed with version 4.3.0
But with marshmallow_dataclass 8.7.0, typeguard gets downgraded to version 4.0.1

$ pip show typeguard
Name: typeguard
Version: 4.3.0
$ pip show marshmallow-dataclass
Name: marshmallow_dataclass
Version: 8.6.1
$ pip show typing-inspect
Name: typing-inspect
Version: 0.8.0
==> OK

vs

$ pip show typeguard
Name: typeguard
Version: 4.0.1
$ pip show marshmallow-dataclass
Name: marshmallow_dataclass
Version: 8.7.0
$ pip show typing-inspect
Name: typing-inspect
Version: 0.9.0
==> SyntaxError: from __future__ imports must occur at the beginning of the file

@epenet
Copy link
Contributor Author

epenet commented Jun 28, 2024

OK - it seems the issue does come from marshmallow-dataclass, which restricts:

  • the typeguard version to ">=4.0.0,<4.1.0"
  • the typing-inspect version to ">=0.9.0,<0.10.0"

install_requires=[
"marshmallow>=3.18.0,",
"typing-inspect~=0.9.0",
"typeguard~=4.0.0",
# Need `dataclass_transform(field_specifiers)`
"typing-extensions>=4.2.0; python_version<'3.11'",
],

Should then not be loosened up?

    install_requires=[
        "marshmallow>=3.18.0,",
        "typing-inspect>=0.9.0",
        "typeguard>=4.0.0",
        # Need `dataclass_transform(field_specifiers)`
        "typing-extensions>=4.2.0; python_version<'3.11'",
    ]

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.

2 participants