GithubHelp home page GithubHelp logo

Comments (5)

DRMacIver avatar DRMacIver commented on August 27, 2024

Confirmed in master.

from yapf.

bwendling avatar bwendling commented on August 27, 2024

YAPF won't do much with this for these reasons:

  1. They can't be put on separate lines unless a -newline is used, which YAPF intentionally doesn't use.
  2. 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.
  3. 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.

DRMacIver avatar DRMacIver commented on August 27, 2024

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.

DRMacIver avatar DRMacIver commented on August 27, 2024

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.

bwendling avatar bwendling commented on August 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.