astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.6k stars 466 forks source link

Trailing newline added when TOML array is empty #1083

Closed my1e5 closed 4 months ago

my1e5 commented 4 months ago

Steps to Reproduce

Create a new rye project and you will see that the empty arrays in pyproject.toml are formatted on one line.

$ rye init hello
$ cd hello/
$ cat pyproject.toml
[project]
name = "hello"
version = "0.1.0"
authors = ...
dependencies = []
readme = "README.md"
requires-python = ">= 3.8"

For example, dependencies = []. If you add a dependency, it will reformat the array like so

$ rye add requests
dependencies = [
    "requests>=2.31.0",
]

But then if you remove that dependency

$ rye remove requests
dependencies = [
]

an extra \n remains.

Expected Result

I expected an empty array to not contain a \n.

dependencies = []

Actual Result

dependencies = [
]

Version Info

$ rye --version
rye 0.33.0
commit: 0.33.0 (58523f69f 2024-04-24)
platform: macos (x86_64)
self-python: cpython@3.12.3
symlink support: true
uv enabled: true

Stacktrace

No response