My IDE is VSCode. I have Black 22.8.0 set as Formatting Provider and IDE is set to format the code on save. This is the first time I apply a code formatter.
This is my Django project structure:
project
|--- settings.py
And this is my pyproject.toml
file:
[tool.black]
line-length = 90
skip-string-normalization = true
extend-exclude = '''(manage.py|settings.py|asgi.py|wsgi.py|urls.py|migrations/*)'''
And the partial output of command black . -v
:
manage.py ignored: matches the --extend-exclude regular expression
project\asgi.py ignored: matches the --extend-exclude regular expression
project\wsgi.py ignored: matches the --extend-exclude regular expression
project\settings.py ignored: matches the --extend-exclude regular expression
So settings.py
is ignored.
But I have this in my settings.py
file:
try:
from dotenv import load_dotenv
load_dotenv
except ImportError:
pass
But if I save this file, it turns into this:
try:
from dotenv import load_dotenv
load_dotenv
except ImportError:
pass
An extra line is added after from
. If I disable Black this won't happen, which means Black is formatting this excluded file.
This is absolutely not a big deal but if Black is not working here, I'm not sure it works anywhere.
Edit 1:
I switched the formatter to autopep8
for test and this didn't happen so definitely its Black. So again, why Black formats an excluded file?