Ok, just to clarify a few points from the text of the specification:
First from this line in the PEP:
When there are multiple comment blocks of the same TYPE
defined, tools MUST produce an error.
Is the intention then that to be compliant all parsers MUST parse the entire file and must not return early?
My implementation currently does return early, but this is a 1 line change so not a huge issue, I just want to know that the intention here was to force parsing of the entire file.
The text description does not give any guidelines on what a TYPE
consists of other than being pyproject
explicitly. The regex picks out only a single word [a-zA-Z0-9-]
match (alphanumeric plus -
). Should this be considered an implementation detail or should TYPE
be more rigorously defined.
Note that I intend to at least warn in the case somebody has written this and doesn’t understand why the block doesn’t work:
# /// pyproject.toml
# ...
# ///
From the discussion, here are examples and what I understand to be the correct behaviour:
Long block of examples
No closing line
example:
# /// pyproject
# [run]
# dependencies = ["requests"]
This block must not be parsed. It is acceptable to either ignore it or raise an exception as it is outside of the scope of the specification to state what to do when encountering something that is not a valid block.
Multiple closing lines
example:
# /// pyproject
# [run]
# dependencies = ["requests"]
# ///
# Additional comment
# ///
This must be parsed as:
[run]
dependencies = ["requests"]
Parsers must stop at the first # ///
.
Multiple opening lines
# /// pyproject
# [run]
# dependencies = ["requests"]
# /// pyproject
# requires-python = ">=3.11"
# ///
This must be parsed as:
[run]
dependencies = ["requests"]
/// pyproject
requires-python = ">3.11"
This will cause an error when passed to the TOML parser at which point additional information can be given if available, but it is not considered an error of the basic block parsing.
Please correct me if I’ve understood any of this incorrectly. I think the behaviour in the case of ‘nested’ blocks intentional or otherwise will be covered by these examples.