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

Failure on import due to version() returning None #451

Open
2 tasks done
EternityForest opened this issue Apr 9, 2024 · 3 comments
Open
2 tasks done

Failure on import due to version() returning None #451

EternityForest opened this issue Apr 9, 2024 · 3 comments
Labels

Comments

@EternityForest
Copy link

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Typeguard version

4.2.0, 4.2.1

Python version

3.10.12

What happened?

I believe this is Python 3.10 specific due to:
python/typeshed#7513

'NoneType' object has no attribute 'split'
  File "/home/daniel/.local/lib/python3.10/site-packages/typeguard/_importhook.py", line 35, in <module>
    OPTIMIZATION = "typeguard" + "".join(version("typeguard").split(".")[:3])
  File "/home/daniel/.local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 178, in exec_module
    exec(co, module.__dict__)
  File "/home/daniel/.local/lib/python3.10/site-packages/typeguard/__init__.py", line 21, in <module>
    from ._importhook import ImportHookManager as ImportHookManager
  File "/home/daniel/.local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 178, in exec_module
    exec(co, module.__dict__)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/lib/python3/dist-packages/importlib_metadata/__init__.py", line 168, in load
    module = import_module(match.group('module'))
  File "/home/daniel/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 414, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/home/daniel/.local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1379, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/home/daniel/.local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1492, in parse
    self._preparse(args, addopts=addopts)
  File "/home/daniel/.local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1143, in pytest_cmdline_parse
    self.parse(args)
  File "/home/daniel/.local/lib/python3.10/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/daniel/.local/lib/python3.10/site-packages/_pytest/helpconfig.py", line 105, in pytest_cmdline_parse
    config = yield
  File "/home/daniel/.local/lib/python3.10/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/daniel/.local/lib/python3.10/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/daniel/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/daniel/.local/lib/python3.10/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/home/daniel/.local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 337, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/home/daniel/.local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 155, in main
    config = _prepareconfig(args, plugins)
  File "/home/daniel/Projects/KaithemAutomation/test_run.py", line 11, in <module>
    sys.exit(pytest.main(["-qq"], plugins=[MyPlugin()]))
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
AttributeError: 'NoneType' object has no attribute 'split'

How can we reproduce the bug?

import typeguard
@agronholm
Copy link
Owner

Typeguard's own test suite would fail on Python 3.10 if this was the case. How did you install it?

@EternityForest
Copy link
Author

That is rather odd and a very good point! I'm not sure why it's so random.

I installed via Poetry, in a project with about 100 other dependencies, but I could do some more digging and try to build a minimal reproduction if needed.

It seems to also occur outside of the virtualenv too, so I would imagine it could be some distro specific nonsense or some other package that breaks stuff if it's present, since the behavior wasn't always there.

For now I'm monkeypatching version() to raise an error if it would normally return None, and everything works fine.

I haven't searched all the different discussions threads but it seems like they are/were talking about making returning None a normal behavior though?

@agronholm
Copy link
Owner

If the package was installed properly, the version("typeguard") should return the version properly. If this is not happening, then you need to figure out why (or provide a MWE).

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

No branches or pull requests

2 participants