You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a piece of code that defines a function differently depending on something in the environment. I feel this is typically formatted as:
if some_condition:
def foo():
do_something()
else:
def foo():
do_something_else()
without whitespace. However, Black (even on master) adds whitespace there before and after the function definition. This certainly makes sense when the function is defined at the top level, but less so inside an if statement, I think.
Here's a full module that would actually parse and run, after formatting by Black:
from contextlib import contextmanager
# This would typically be computed by a function inspecting the environment...
ENABLED = True
if ENABLED:
@contextmanager
def foo(msg, *args, **kwargs):
print(msg.format(*args, **kwargs))
yield
print("Done!")
else:
@contextmanager
def foo(msg, *args, **kwargs):
yield
Again, I would personally have expected this to be written without blank lines after the if and around the else. Thoughts?
The text was updated successfully, but these errors were encountered:
I'm writing a piece of code that defines a function differently depending on something in the environment. I feel this is typically formatted as:
without whitespace. However, Black (even on master) adds whitespace there before and after the function definition. This certainly makes sense when the function is defined at the top level, but less so inside an if statement, I think.
Here's a full module that would actually parse and run, after formatting by Black:
Again, I would personally have expected this to be written without blank lines after the
if
and around theelse
. Thoughts?The text was updated successfully, but these errors were encountered: