psf / psf/black

Black's public API

Open
#779 22 comments 17 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C: api T: enhancement
Dominant language
Python
Stars
41.8k
Forks
2.9k
Avg merge
5d 6h
Merged PRs (30d)
9

Description

With previous versions, it was possible to just use black.format_str(string) or black.format_str(string, line_length=82).

Now one needs to do:

black.format_str(string, mode=black.FileMode(line_length=82))

It's not a big deal in a module, but format_str was also useful in notebooks to display examples of Python code programmatically generated (for example by astunparse.unparse(tree)).

Therefore, it could be nice to support also black.format_str(string) and black.format_str(string, line_length=82).

The line_length argument is useful when one wants to get code adapted for a presentation (made with Jupyter for example).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the public black.format_str API and inspect how it currently accepts FileMode, including the existing line_length handling. Confirm the desired calls work with and without an explicit line length, then run the relevant formatter API tests or add coverage for those calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.