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
If Bar does not have a decorator, black permits the empty line between the two definitions. I think the empty line improves readability here quite a bit, so I'd prefer it if black would allow (or even enforce it). Decorated classes haven't historically been very common in stub files (previously, I think the only major one was maybe @final?), but we'll get more of them now that we have @deprecated: see python/typeshed#11488
The text was updated successfully, but these errors were encountered:
I tried fixing this but ran into some issues. Writing this as a reference for anyone else who decides to try.
For context, Black’s current style is to add blank lines around all stub classes. No blank lines are added between function stubs. The issue is that both classes and functions can be decorated. Decorated stub classes next to each other behave correctly since there’s always a blank line around them. We want to keep stub functions together, even if there’s a decorator, which works well. The issue arises when you mix and match stub functions, stub classes, and decorators.
Take the example raised in this issue:
deffoo(): ...
@decoratorclassBar: ...
While determining whether to add empty lines around a line of code, Black has access to the current and previous lines of code. We can't add a line before @decorator() because the following line could be a def, and defs should always stay together. We can't add a line after def foo(): ... simply because it currently has no way of knowing what comes next, and that there should be a blank line there.
There’s probably still a fix here, but it’d require more substantial refactors to Black’s code.
Describe the bug
Black reformats the following
.pyi
stub file:to this:
If
Bar
does not have a decorator, black permits the empty line between the two definitions. I think the empty line improves readability here quite a bit, so I'd prefer it if black would allow (or even enforce it). Decorated classes haven't historically been very common in stub files (previously, I think the only major one was maybe@final
?), but we'll get more of them now that we have@deprecated
: see python/typeshed#11488The text was updated successfully, but these errors were encountered: