ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.91k stars 1.68k forks source link

ImportError while using in pytest #3346

Closed makhtev closed 3 months ago

makhtev commented 3 months ago

What happened?

ImportError: cannot import name 'ContractName' from 'eth_typing' (/opt/venv/lib/python3.10/site-packages/eth_typing/init.py)

After this commit, old version of web3 not working anymore with pytest.

Code that produced the error

import web3
import pytest

pytest.console_main()

Full error output

Traceback (most recent call last):
  File "/usr/local/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 197, in console_main
    code = main()
  File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 155, in main
    config = _prepareconfig(args, plugins)
  File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 337, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/usr/local/lib/python3.10/site-packages/_pytest/helpconfig.py", line 105, in pytest_cmdline_parse
    config = yield
  File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 102, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1143, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1492, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1379, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 414, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/local/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 178, in exec_module
    exec(co, module.__dict__)
  File "/usr/local/lib/python3.10/site-packages/web3/tools/__init__.py", line 1, in <module>
    from .pytest_ethereum import (
  File "/usr/local/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 178, in exec_module
    exec(co, module.__dict__)
  File "/usr/local/lib/python3.10/site-packages/web3/tools/pytest_ethereum/deployer.py", line 7, in <module>
    from eth_typing import (
ImportError: cannot import name 'ContractName' from 'eth_typing' (/usr/local/lib/python3.10/site-packages/eth_typing/__init__.py)

Fill this section in if you know how this could or should be fixed

Freeze eth_typing to minor version in dependencies

web3 Version

6.10.0

Python Version

3.10.13

Operating System

linux

Output from pip freeze

aiohttp==3.9.4
aiosignal==1.3.1
annotated-types==0.6.0
async-timeout==4.0.3
attrs==23.2.0
bitarray==2.9.2
certifi==2024.2.2
charset-normalizer==3.3.2
ckzg==1.0.0
cytoolz==0.12.3
eth-account==0.12.2
eth-hash==0.7.0
eth-keyfile==0.8.0
eth-keys==0.5.0
eth-rlp==2.1.0
eth-typing==4.2.0
eth-utils==4.1.0
eth_abi==5.1.0
exceptiongroup==1.2.0
frozenlist==1.4.1
hexbytes==1.2.0
idna==3.7
iniconfig==2.0.0
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
lru-dict==1.3.0
multidict==6.0.5
packaging==24.0
parsimonious==0.10.0
pluggy==1.4.0
protobuf==5.26.1
pycryptodome==3.20.0
pydantic==2.7.0
pydantic_core==2.18.1
pytest==8.1.1
pyunormalize==15.1.0
referencing==0.34.0
regex==2023.12.25
requests==2.31.0
rlp==4.0.0
rpds-py==0.18.0
tomli==2.0.1
toolz==0.12.1
typing_extensions==4.11.0
urllib3==2.2.1
web3==6.10.0
websockets==12.0
yarl==1.9.4
reedsa commented 3 months ago

We have a patch to fix this issue and will be released first thing tomorrow.

Until then, please continue to use the pin you mentioned.

reedsa commented 3 months ago

This should be fixed in https://github.com/ethereum/web3.py/tree/v6.17.2

Apologies for this issue, eth-typing v4.2.0 is not a usable release, this was patched and marked as excluded by web3.py.