Comments (5)
Confirmed in master.
from yapf.
YAPF won't do much with this for these reasons:
- They can't be put on separate lines unless a -newline is used, which YAPF intentionally doesn't use.
- We could try to add parentheses around the imports, but I don't like that idea much either. Adding or removing elements in a file can be tricky and I feel it falls outside the scope of a reformatter.
- If the import lines were separated, they would have to be ordered alphabetically, which again is outside of the scope of a reformatter.
Both (2) and (3) are more along the lines of a refactoring tool (see the rope library). I could see this as a 2to3 fixer in a "contrib" directory. But even that's iffy...
from yapf.
Ah, so an important detail that you wouldn't know because I completely failed to mention it, sorry, is that the problem here is that yapf is doing something! My objection isn't that yapf isn't fixing it, it's that yapf is breaking it in the first place. The provided example was originally:
from __future__ import division, print_function, absolute_import, \
unicode_literals
Which is perfectly valid formatting, and yapf produced the single line variant.
from yapf.
Incidentally, I already handle getting imports correct and sorted using the isort library. In my current work flow I run that before pyformat, but I could change that to solve this problem by running yapf before isort. It's just a shame to introduce errors that weren't present in the original source.
from yapf.
Well, as I mentioned we intentionally don't use backslash-newlines. IMHO, they are a blight on proper code. Note that the import statement above goes against the PEP 8 style guide (https://www.python.org/dev/peps/pep-0008/#imports). Also, I believe that import statements are immune from pylint warnings about going over 80 columns.
from yapf.
Related Issues (20)
- Remove the blank line between docstring and function head
- Improve error reporting when `yapf` encounters unsupported Python syntax
- Set specific options for keywords
- Function call without arguments.
- Yapf not formatting python generic HOT 1
- dedent_closing_brackets not working for Annotations[]
- yapf is failing `pre-commit` with `tool.yapfignore` configured: `yapf: input filenames did not match any python files`
- [BUG] yapf with split_all_top_level_comma_separated_values set to true fails to split lines with tuple LHS HOT 1
- [Bug] [Crash][Reproducible] `EOFError: Ran out of input` when import yapf with multiprocess
- assert formatting
- Strange inconsistent behaviour HOT 3
- Is there a each_dict_entry_on_separate_line for lists? HOT 2
- Try to keep list literals in tuples aligned
- yapf-diff inconsistent with yapf on multiline strings with backslashes
- Ternary conditionals within F Strings Raise IndexError
- Split type hints with trailing comma
- yapf adds spaces before backslash with every run
- Split first and only argument into separate line
- The formatter fails in this file
- Is there a way to `ALLOW_MULTILINE_LISTS`? HOT 1
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 yapf.