Skip to content

Commit fd07001

Browse files
committed
Fix misdetection of project root with --stdin-filename
There are a number of places this behaviour could be patched, for instance, it's quite tempting to patch it in `get_sources`. However I believe we generally have the invariant that project root contains all files we want to format, in which case it seems prudent to keep that invariant. Fixes psf#3207
1 parent 507234c commit fd07001

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/black/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,11 @@ def main( # noqa: C901
468468
out(main.get_usage(ctx) + "\n\nOne of 'SRC' or 'code' is required.")
469469
ctx.exit(1)
470470

471-
root, method = find_project_root(src) if code is None else (None, None)
471+
if stdin_filename is not None:
472+
src_with_stdin_filename = tuple(stdin_filename if s == "-" else s for s in src)
473+
else:
474+
src_with_stdin_filename = src
475+
root, method = find_project_root(src_with_stdin_filename) if code is None else (None, None)
472476
ctx.obj["root"] = root
473477

474478
if verbose:

0 commit comments

Comments
 (0)