I’m not going to update the PEP because (a) I’ve said it’s ready for review and I don’t want to keep changing it after that, and (b) the “Rejected Alternatives” section is already huge, and I don’t think there’s a lot of value in extending it further. However, I will respond here, for the record.
First of all, I do actually think this is covered adequately by Why not use (possibly restricted) Python syntax? That section as written is focused more on the __requirements__ = [...]
idea, but that’s because that was the commonest suggestion of this form at the time, but it’s not exclusive to that form.
You’re misunderstanding my point here. To find the docstring, you need to identify the “first string literal in the file”. And to do that you either need a Python parser or you define a restricted syntax for the docstrings you are willing to parse. For example,
"""
Script dependencies:
\N{Latin small letter r}equests
"""
is a valid docstring. Would you accept that as declaring a dependency on requests? Yes, you can find it easily enough, but you can’t parse it with just a regex, for example.
And if you do need a full Python parser, you hit all of the issues raised in the PEP about tying the client to a particular Python version, being hard to write clients in languages other than Python, the Python AST compiler having no easy to use “incremental” mode, etc, etc.
rf
strings aren’t valid docstrings. So you’re safe there. But this emphasises my point that it’s really hard to be precise about the syntax if you define it in terms of Python constructs, and really hard to define something that evaluates to the same thing statically and at runtime if you don’t. And I think having something that has different values statically and at runtime is a bad source of potential bugs and confusion.
Yes, this is to some extent about weird edge cases, but IMO that’s the key job of a PEP, to address weird edge cases. Anyone can write something that “usually” works, but once it hits the reality of multiple implementations and users that each interpret the spec their own way, vagueness is a big problem.
Sure, it requires some familiarity to know how to specify your dependencies. But “allowing people to write a dependency block without any prior knowledge” was never a goal here. “You write your dependencies in a specially structured comment” isn’t a big thing to expect people to learn.
Also, people use __doc__
at runtime, and expecting those people to have to decide whether putting a dependency block in the docstring, where it will affect the existing usage of __doc__
(which is often user-visible) is a problem. Especially if there’s no alternative - and I hope you aren’t suggesting allowing a dependency block in the docstring as well as in a comment, because having two ways of doing this seems like it’s way too much.
I hope that explains why I don’t think the argument in the PEP is particularly weak, it’s just that it isn’t specifically framed in terms of docstrings.