Skip to content

Commit

Permalink
Accommodates find_pyproject_toml returning None
Browse files Browse the repository at this point in the history
Prior to this, the return value of `black.files.find_pyproject_toml` was passed directly
to `os.path.exists`. This was fine where `black` could find a `pyproject.toml` file.
However, when one cannot be located, `find_pyproject_toml` returns `None`, which results
in an uncaught exception from `os.path.exists`. This adds an additional check for when
`find_project_toml` returns `None`.

Fixes #1955 (introduced by #1950).
  • Loading branch information
posita committed Jan 12, 2022
1 parent 9e4382f commit 5d3d329
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion elpy/blackutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def fix_code(code, directory):
pyproject_path = find_pyproject_toml((directory,))
else:
pyproject_path = os.path.join(directory, "pyproject.toml")
if toml is not None and os.path.exists(pyproject_path):
if toml and pyproject_path and os.path.exists(pyproject_path):
pyproject_config = toml.load(pyproject_path)
black_config = pyproject_config.get("tool", {}).get("black", {})
if "line-length" in black_config:
Expand Down

0 comments on commit 5d3d329

Please sign in to comment.