Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERA001 stops parsing an inline script metadata block at the first # /// line #13278

Closed
dscorbett opened this issue Sep 7, 2024 · 1 comment · Fixed by #13283
Closed

ERA001 stops parsing an inline script metadata block at the first # /// line #13278

dscorbett opened this issue Sep 7, 2024 · 1 comment · Fixed by #13283
Assignees
Labels
bug Something isn't working rule Implementing or modifying a lint rule

Comments

@dscorbett
Copy link

ERA001 skips PEP 723 inline script metadata blocks as of #10455, except that it stops skipping after the first # /// line. However, a metadata block continues if the following lines are valid embedded content followed by another # /// line. ERA001 should skip over the full metadata block.

For example, this script (named era001.py) contains metadata with an embedded # /// line.

# /// script
# [tool.uv]
# extra-index-url = ["https://pypi.org/simple", """\
# https://example.com/
# ///
# """
# ]
# ///
print(1)

The script works, which shows that the first # /// line does not end the block. (I am using uv, but this could work with any tool that interprets inline metadata.)

$ uv version
uv 0.4.7 (a178051e8 2024-09-07)
$ uv run era001.py
Reading inline script metadata from: era001.py
1

However, Ruff reports an error.

$ ruff --version
ruff 0.6.4
$ ruff check --isolated --select ERA001 era001.py
era001.py:7:1: ERA001 Found commented-out code
  |
5 | # ///
6 | # """
7 | # ]
  | ^^^ ERA001
8 | # ///
9 | print(1)
  |
  = help: Remove commented-out code

Found 1 error.
@MichaReiser MichaReiser added bug Something isn't working rule Implementing or modifying a lint rule labels Sep 8, 2024
@MichaReiser
Copy link
Member

Thanks. From the PEP:

Precedence for an ending line # /// is given when the next line is not a valid embedded content line as described above. For example, the following is a single fully valid block:

# /// some-toml
# embedded-csharp = """
# /// <summary>
# /// text
# ///
# /// </summary>
# public class MyClass { }
# """
# ///

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants