question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce formatter

See original GitHub issue

Motivation

If we introduce a formatter to Optuna and just use it, we do not need to think about formatting.

Description

There are famous formatters in python:

  1. autopep8 (current)
  2. Black
    • example of applying black #957
  3. yapf

c.f. https://blog.frank-mich.com/python-code-formatters-comparison-black-autopep8-and-yapf/

We need to discuss what formatter is best.

Differences of above formatters

black

  • Use " instead of '.
  • Add trailing commas to expressions that are split by comma where each element is on its own line.
  • Break a line before a binary operator when splitting a block of code over multiple lines.

black vs yapf

c.f. https://news.ycombinator.com/item?id=17155048

  • YAPF would at times not produce deterministic formatting (formatting the same file the second time with no changes in between would create a different formatting); Black treats this as a bug;
  • YAPF would not format all files that use the latest Python 3.6 features (we have a lot of f-strings, there’s cases of async generators, complex unpacking in collections and function calls, and so on); Black solves that;
  • YAPF is based on a sophisticated algorithm that unwinds the line and applies “penalty points” for things that the user configured they don’t like to see. With a bit of dynamic programming magic it arrives at a formatting with the minimal penalty value. This works fine most of the time. When it doesn’t, and surprised people ask you to explain, you don’t really know why. You might be able to suggest changing the penalty point value of a particular decision from, say, 47 to 48. It might help with this particular situation… but break five others in different places of the codebase.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
keisuke-umezawacommented, Feb 24, 2020

imo, I want to use black as our formatter.

1reaction
hvycommented, Mar 17, 2020

I created a PR addressing above comment https://github.com/optuna/optuna/pull/1030 (c.f. https://github.com/optuna/optuna/pull/1020#issuecomment-599403792). It has now been merged so let me close this issue. Thanks a lot @keisuke-umezawa for the long running investigation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing the Q# Formatter - Microsoft Developer Blogs
Introducing the Q# Formatter · Unit Type References – Replaces () with Unit when referencing the Unit type (for example, in callable signatures)....
Read more >
Introduction to Formatting the Essay
The first box is the Introductory Paragraph. As the visual above shows, these three types of paragraphs combine to form an essay. In...
Read more >
formatter-maven-plugin – Introduction
Introduction. Maven plugin for formatting source code. This plugin allows formatting java source code using the Eclipse code formatter.
Read more >
How to introduce a code formatter without messing up Git history
How to introduce a code formatter without messing up Git history. We still want to see who and why a line of code...
Read more >
Introduction to Formatting
Formatting is the process of turning the result of an XSL transformation into a tangible form for the reader or listener. This process...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found