isort icon indicating copy to clipboard operation
isort copied to clipboard

Different behavior for some options when passed as kwargs vs file

Open kmurphy4 opened this issue 3 years ago • 0 comments

Hi, I'm noticing some different behavior in how isort.Config is handling string arguments depending on how they're passed in.

In this case, I think it was actually a bug in my code that I was assuming a particular option was intended to be a str, whereas it was actually expected to be an Iterable[str]. Nevertheless, I wouldn't expect to get different results!

Here's a simple reproduction:

import isort
import os
import tempfile
import toml

KNOWN_FIRST_PARTY = "firstparty"  # this should really be `["firstparty"]`

with tempfile.TemporaryDirectory() as tmpdir:
    path = os.path.join(tmpdir, "pyproject.toml")
    data = {
        "tool": {
            "isort": {
                "known_first_party": KNOWN_FIRST_PARTY,
            },
        }
    }
    with open(path, "w") as f:
        toml.dump(data, f)
    from_file = isort.Config(settings_path=path)
print(from_file.known_first_party)    # => `frozenset({'firstparty'})`

from_kwargs = isort.Config(known_first_party=KNOWN_FIRST_PARTY)
print(from_kwargs.known_first_party)  # => `frozenset({'t', 's', 'a', 'y', 'i', 'f', 'p', 'r'})`
environment details
$ python3 --version
Python 3.6.9

$ python3 -c 'import isort; print(isort.__version__)'
5.10.1

$ uname -a
Linux bandos 5.3.0-40-generic #32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

kmurphy4 avatar Jan 07 '22 23:01 kmurphy4