tox-dev / tox

Command line driven CI frontend and development task automation tool.
https://tox.wiki
MIT License
3.68k stars 521 forks source link

TypeError: isinstance() argument 2 cannot be a parameterized generic #3287

Closed ssbarnea closed 5 months ago

ssbarnea commented 5 months ago

Issue

Stacktrace with tox when loading plugin configuration. Based on the error displayed I believe that is not the plugin fault. The loaded configuration option is a list, like below:

[ansible]
skip =
    py3.7
    py3.8
    2.9
    2.10
    2.11
    2.12
    2.13

I am still trying to fully understand this python typing issue in order to know how to avoid it.

Environment

Provide at least:

Output of pip list of the host Python, where tox is installed ```console ROOT: Using a default tox.ini file with tox-ansible plugin is not recommended. Consider using a tox-ansible.ini file and specify it on the command line (`tox --ansible -c tox-ansible.ini`) to avoid unintentionally overriding the tox-ansible environment configurations. Traceback (most recent call last): File "/Users/ssbarnea/.asdf/installs/python/3.12.3/bin/tox", line 8, in sys.exit(run()) ^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/run.py", line 20, in run result = main(sys.argv[1:] if args is None else args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/run.py", line 42, in main result = provision(state) ^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/provision.py", line 86, in provision MANAGER.tox_add_core_config(state.conf.core, state) File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/plugin/manager.py", line 79, in tox_add_core_config self.manager.hook.tox_add_core_config(core_conf=core_conf, state=state) File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/pluggy/_hooks.py", line 513, in __call__ return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall raise exception.with_traceback(exception.__traceback__) File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/pluggy/_callers.py", line 103, in _multicall res = hook_impl.function(*args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/c/a/tox-ansible/src/tox_ansible/plugin.py", line 168, in tox_add_core_config env_list = add_ansible_matrix(state) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/c/a/tox-ansible/src/tox_ansible/plugin.py", line 266, in add_ansible_matrix env for env in env_list.envs if all(skip not in env for skip in ansible_config["skip"]) ~~~~~~~~~~~~~~^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/config/sets.py", line 116, in __getitem__ return self.load(item) ^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/config/sets.py", line 127, in load return config_definition.__call__(self._conf, self.loaders, ConfigLoadArgs(chain, self.name, self.env_name)) # noqa: PLC2801 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/config/of_type.py", line 103, in __call__ value = loader.load(key, self.of_type, self.factory, conf, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/config/loader/api.py", line 144, in load converted = self.build(key, of_type, factory, conf, raw, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/config/loader/ini/__init__.py", line 85, in build converted = self.to(prepared, of_type, factory) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ssbarnea/.asdf/installs/python/3.12.3/lib/python3.12/site-packages/tox/config/loader/convert.py", line 42, in to if isinstance(raw, of_type): # already target type no need to transform it ^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: isinstance() argument 2 cannot be a parameterized generic```

Output of running tox

Output of tox -rvv ```console ```

Minimal example

https://github.com/ansible-collections/cisco.nxos/actions/runs/9277917412/job/25528009504

ssbarnea commented 5 months ago

I found the change in tox-ansible that triggered this error, and it was an auto-fix from ruff, replacing List[] type annotation with list[], which is perfectly normal considering the used versions of python.

I will now check to see if I can change the type checking in tox itself to prevent it from happening anyway.