TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

YAPF – A formatter for Python files

142 pointsby sudmishraabout 10 years ago

14 comments

rbanffyabout 10 years ago
<p><pre><code> --style STYLE specify formatting style: either a style name (for example &quot;pep8&quot; or &quot;google&quot;), or the name of a file with style settings. pep8 is the default. </code></pre> &gt; pep8 is the default.<p>I can breathe again.
评论 #9314914 未加载
评论 #9313169 未加载
bkcooperabout 10 years ago
I&#x27;m sure there are some cases where this is useful, but I&#x27;m not really sold. The pitch at the beginning is &quot;satisfying PEP 8 doesn&#x27;t mean it looks good!&quot; But then it seems most of the changes cleaned up in the code (indentation level, indents on split lines, spacing between operators) are just PEP 8 violations. I think you could find a more convincing demonstration.<p>The warning about choking on large data literals (which are probably one of the places where prettifying would be most useful, at least to me) also seems ominous.<p>edit: for my personal use, I tend to use flycheck with flake8 in emacs. This keeps me honest. Is the primary use case for something like this cleaning your own code or other people&#x27;s?
评论 #9313988 未加载
评论 #9313269 未加载
评论 #9314573 未加载
评论 #9313205 未加载
B4CKlashabout 10 years ago
&gt;YAPF is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.
评论 #9313710 未加载
Pirate-of-SVabout 10 years ago
I&#x27;ve been using YAPF for a while and I really like the idea. Be aware that there are still some nasty bugs that haven&#x27;t been fixed yet so be careful if you use it for something important.<p>Do anyone of you guys know what the name YAPF comes from? (The only thing I can think of is &quot;Yet Another Python Formatter&quot;, but I&#x27;m just guessing)
评论 #9313980 未加载
Fuzzwahabout 10 years ago
I&#x27;ve got a python project where I&#x27;ve been pretty naughty with long lines containing sql queries.<p>I found that running this tool over it resulted in some strange new lines.<p>For example, this was my old hideously long line:<p>query_qual = &quot;INSERT OR REPLACE INTO Qualifying (poleid, seasonid, race_week_num, carclassid, pole) values (%s%s, %s, %s, %s, %s)&quot; % (race[u&#x27;seasonid&#x27;], race[u&#x27;race_week_num&#x27;], race[u&#x27;seasonid&#x27;], race[u&#x27;race_week_num&#x27;], race[u&#x27;carclassid&#x27;], pole)<p>Changed to this:<p>query_qual = &quot;INSERT OR REPLACE INTO Qualifying (poleid, seasonid, race_week_num, carclassid, pole) values (%s%s, %s, %s, %s, %s)&quot; % ( race[u&#x27;seasonid&#x27;], race[u&#x27;race_week_num&#x27;], race[ u&#x27;seasonid&#x27; ], race[u&#x27;race_week_num&#x27;], race[u&#x27;carclassid&#x27;], pole)
评论 #9314018 未加载
评论 #9313483 未加载
评论 #9313468 未加载
评论 #9313978 未加载
alok-gabout 10 years ago
Off-topic, but why is no space before opening parenthesis the norm in programming (&quot;class foo(object):&quot;) when normal English usage is to have one? I know myself as the only one who puts this space.
评论 #9314527 未加载
评论 #9314483 未加载
评论 #9314486 未加载
pdknskabout 10 years ago
This passed HN duplicate detector, despite same URL and submission title.<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9260786" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9260786</a>
zk00006about 10 years ago
Is it possible to YAPF it in Sublime?
评论 #9342772 未加载
评论 #9314548 未加载
teddyhabout 10 years ago
There seems to be a problem parsing backslash escapes:<p>echo &#x27;foo=&quot;\\&quot;&#x27; | PYTHONPATH=&#x2F;tmp&#x2F;yapf&#x2F;yapf python &#x2F;tmp&#x2F;yapf<p>Raises a lib2to3.pgen2.parse.ParseError.<p>Also crashes on \n, but not, strangely, on \t.<p>I’m guessing that the backslashes get interpreted twice, somehow.
评论 #9313981 未加载
kolanosabout 10 years ago
I definitely would like to see configuration options for the vertical alignment of arguments. If the arguments don&#x27;t fit within the line length then having the option to put them on separate lines (still pep8) would be nice.
fweespeechabout 10 years ago
&gt; YAPF is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.<p>Just in case anyone thought &quot;by Google&quot; meant &quot;a Google product&quot; like me.
mas1nabout 10 years ago
Interesting to see the formatter is written using 2 space indentation when both pep8 and google&#x27;s style guides say 4.
评论 #9313280 未加载
baqabout 10 years ago
i use autopep8 and haven&#x27;t been thrilled. it gets the job done, but i&#x27;ll switch in a heartbeat if this is better. we&#x27;ll see.
评论 #9314560 未加载
评论 #9313985 未加载
sergiotapiaabout 10 years ago
Also see go fmt
评论 #9313464 未加载