News

Community Dev Gives VS Code Python Some YAPF

The latest update to Python in Visual Studio Code includes a new extension for Python formatting that was contributed by a member of the open source community.

The tool, titled simply yapf, is currently in preview, published by "EeyoreLee" to provide functionality that originated with Google's YAPF initiative, commonly understood to stand for "yet another Python formatter," though that description isn't mentioned in Google's YAPF GitHub repo.

The repo does say that YAPF (Goole uses uppercase, Microsoft/EeyoreLee use lowercase) is based on Daniel Jasper's clang-format and provides an algorithm to take code and calculate the best formatting that conforms to the configured style in order to lessen the drudgery of maintaining the code. "The ultimate goal is that the code YAPF produces is as good as the code that a programmer would write if they were following the style guide," Google's repo says.

Microsoft, meanwhile, this month said, "This extension provides yapf formatting support for Python files and Notebook cells" in announcing the September 2023 update to Python in VS Code. "Yapf support built into the Python extension will be deprecated in favor of the extension support. Subsequently, the corresponding setting python.formatting.yapf will be removed from the Python extension."

[Click on image for larger view.] yapf (source: VS Code Marketplace).

The extension, which was last updated today (Sept. 25), is nearing 3,000 installs at the time of this writing, receiving a perfect 5.0 rating from one developer who reviewed it.

Then removal of the bits from Microsoft's main Python extension is part of the team's effort started last year to break up its big extension into separate tools. "Our team is working towards breaking the tools support we offer in the Python extension into separate extensions, with the intent of improving performance, stability and no longer requiring the tools to be installed in a Python environment -- as they can be shipped alongside an extension," Microsoft said last year.

The new update also features an experiment in which the Python extension uses environment variables to activate terminals implicitly on terminal launch to provide a faster experience, especially for conda users.

"This month, we are beginning the rollout of terminal activation using environment variables that activate the selected environment in the terminal without requiring any activation commands," the announcement post said. As an experiment, it will be rolled out as the default for 25 percent of pre-release users via a flag that devs can use to opt in or out of the test.

The team also updated the Python: Create Environment command to let devs choose to either recreate or use the existing environment when working on a project working within a workspace that already contains a .venv folder.

The team is responsible for the Python extension (98 million installs) and the Jupyter extension (70.5 million installs) in the VS Code Marketplace. Along with the company's Pylance extension, those tools are the top three most popular offerings in the marketplace.

Other changes and enhancements as listed in the post include:

  • Unresolved import errors now indicate in which environment Pylance is looking for packages (pylance-release#4368)
  • There's a new experimental setting called python.analysis.enableSyncServer that enables multi-file IntelliSense support in vscode.dev. Support for github.dev and virtual workspaces is coming soon.
  • Pylance no longer crashes on Jupyter Notebook cell deletion (@pylance-release#4685)
  • There is a new dedicated topic on Python formatting in our docs where you'll learn how to set a default formatter such as autopep8 or Black formatter and customize it through various settings.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Uno Platform Wants Microsoft to Improve .NET WebAssembly in Two Ways

    Uno Platform, a third-party dev tooling specialist that caters to .NET developers, published a report on the state of WebAssembly, addressing some shortcomings in the .NET implementation it would like to see Microsoft address.

  • Random Neighborhoods Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the random neighborhoods regression technique, where the goal is to predict a single numeric value. Compared to other ML regression techniques, advantages are that it can handle both large and small datasets, and the results are highly interpretable.

  • As Some Orgs Restrict DeepSeek AI Usage, Microsoft Offers Models and Dev Guidance

    While some organizations are restricting employee usage of the new open source DeepSeek AI from a Chinese company due to data collection concerns, Microsoft has taken a different approach.

  • Useful New-ish Features in .NET/C#

    We often hear about the big new features in .NET or C#, but what about all of those lesser known, but useful new features? How exactly do you use constructs like collection indices and ranges, date features, and pattern matching?

  • TypeScript 5.8 Beta Speeds Program Loads, Updates

    "TypeScript 5.8 introduces a number of optimizations that can both improve the time to build up a program, and also to update a program based on a file change in either --watch mode or editor scenarios."

Subscribe on YouTube