Search code examples
pythondictionarypytest

What is the difference between ConfigDict and dict?


What is the difference between ConfigDict and dict?

ConfigDict: TypeAlias = dict[str, Union[str, list[str]]]

What are the advantages of using ConfigDict?

https://github.com/pytest-dev/pytest/pull/13193/files#diff-f1d27932fbd9530086080aa8df367309881fe90f204cdd69102ba59758644761


Solution

  • ConfigDict in the PR you linked to is a type alias to a dict where the key is a string and the value is either a string or a list of strings.

    In runtime, there isn't any functional difference. It's mainly useful in development time to save having to type the long dict definition each time and to avoid mistakenly using a different definition (e.g., using dict(str, str) by mistake.