Comments (4)
I think the trick here is not to add a line. But if the user added a line it's probably fine.
from blue.
I was reading through the Black source code and thought this looked pretty good:
@dataclass
class Line:
"""Holds leaves and comments. Can be printed with `str(line)`."""
depth: int = 0
leaves: List[Leaf] = field(default_factory=list)
# keys ordered like `leaves`
comments: Dict[LeafID, List[Leaf]] = field(default_factory=dict)
bracket_tracker: BracketTracker = field(default_factory=BracketTracker)
inside_brackets: bool = False
should_explode: bool = False
def append(self, leaf: Leaf, preformatted: bool = False) -> None:
"""Add a new `leaf` to the end of the line.
Unless `preformatted` is True, the `leaf` will receive a new consistent
whitespace prefix and metadata applied by :class:`BracketTracker`.
Trailing commas are maybe removed, unpacked for loop variables are
demoted from being delimiters.
Inline comments are put aside.
"""
has_value = leaf.type in BRACKETS or bool(leaf.value.strip())
...
Notice the blank line after the class's docstring and then another blank line after the class's vars. I think that looks pretty good. I wonder if it's this logic that applies also to functions.
Also notice that the function's multi-line docstring has no blank line succeeding it.
from blue.
As the demo code in #39 shows, I think Black's handling here is good. The rule seems to be that a blank line always follows a class docstring but not so for a function. I hadn't realized that when we discussed this issue before.
I think I could accept Black's formatting here.
from blue.
If you're right about the class/function distinction, then I'm cool with it, and my case isn't special enough to break the rules.
from blue.
Related Issues (20)
- [docs request] Examples of pyproject.toml and setup.cfg
- [Question] Active? HOT 2
- 0x and 0b case
- Coverage requirement fails
- Exclude not workin pyproject.toml
- error: cannot format main.py: Cannot parse: 66:21 HOT 1
- blue is incompatible with flake8 v5 HOT 9
- Unable to run Blue formatting HOT 4
- Don't expand brackets
- How to properly use Blue in GitHub Actions? HOT 1
- https://iblueit.dev/ is broken due to missing resources HOT 1
- Don't bind specific versions of `black`, monkey patch methods on `ast` level
- Continuation lines defined by extra indentation HOT 1
- Comply with PEP-8 for indentation of parameters in function definition HOT 3
- leave function-scope imports alone
- [docs request] Adding example pre-commit config to README
- Is this repository still active? The last update was 9 month ago HOT 4
- Doc: how to use blue with vscode? HOT 1
- Vim Plugin for blue HOT 5
- blue changes `%autoreload 2` in jupyter ntoebooks to random hex
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blue.