Skip to content

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

@ssbarnea

Description

@ssbarnea

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:

  • OS:
Output of pip list of the host Python, where tox is installed
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 <module>
    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```

</details>

## Output of running tox

<details open>
<summary>Output of <code>tox -rvv</code></summary>

```console

Minimal example

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:minordoes not affect many people or has no big impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions