google / yapf

A formatter for Python files
Apache License 2.0
13.75k stars 888 forks source link

Auto-discover and format `.pyi` files. #1151

Closed elenakrittik closed 11 months ago

elenakrittik commented 1 year ago

.pyi files (used primarily in type stubs) are also valid Python files, therefore it would be great if yapf would discover and format them automatically (like it currently does with .py files).

hartwork commented 11 months ago

From a quick look, maybe this is the only place that needs patching…

https://github.com/google/yapf/blob/3d4986ee86be97f7b26bb737743ffbda2cc18c27/yapf/yapflib/file_resources.py#L253-L258

…and maybe an additional test.

bwendling commented 11 months ago

Okay, but I think it should be done via a flag of some sort. Maybe a knob where you can specify the file extensions you'd like formatted?

hartwork commented 11 months ago

@bwendling is that really necessary?

bwendling commented 11 months ago

If the only time there'd be a .pyi file is for type stubs, then I suppose not.

hartwork commented 11 months ago

@bwendling cool! :+1:

elenakrittik commented 11 months ago

Thank you!