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

Support PEP 695 syntax for class definitions #11438

Closed
JelleZijlstra opened this issue May 23, 2023 · 2 comments · Fixed by #11444
Closed

Support PEP 695 syntax for class definitions #11438

JelleZijlstra opened this issue May 23, 2023 · 2 comments · Fixed by #11444

Comments

@JelleZijlstra
Copy link

PEP 695, which is implemented in the upcoming Python 3.12, adds a new syntax for defining generic classes:

class Sequence[T]:
     def __getitem__(self, idx: int) -> T: ...

I would like to document generic classes with e.g. .. class:: Sequence[T], but that doesn't render correctly (the class introduction doesn't appear):

Screen Shot 2023-05-22 at 8 34 55 PM

Presumably the parser for the class directive needs to be taught to recognize this syntax. (Cross-ref: python/cpython#104642 (comment).)

@picnixz
Copy link
Member

picnixz commented May 23, 2023

The issue lies in

# REs for Python signatures
py_sig_re = re.compile(
r'''^ ([\w.]*\.)? # class name(s)
(\w+) \s* # thing name
(?: \(\s*(.*)\s*\) # optional: arguments
(?:\s* -> \s* (.*))? # return annotation
)? $ # and nothing more
''', re.VERBOSE)

We need a better regular expression for matching this new signature. If anyone knows some magical regex for that (otherwise I'll think of it this w-e).

picnixz added a commit to picnixz/sphinx that referenced this issue May 28, 2023
picnixz added a commit to picnixz/sphinx that referenced this issue May 28, 2023
picnixz added a commit to picnixz/sphinx that referenced this issue May 28, 2023
picnixz added a commit to picnixz/sphinx that referenced this issue May 28, 2023
picnixz added a commit to picnixz/sphinx that referenced this issue May 28, 2023
picnixz added a commit to picnixz/sphinx that referenced this issue May 28, 2023
picnixz added a commit to picnixz/sphinx that referenced this issue May 28, 2023
picnixz added a commit to picnixz/sphinx that referenced this issue May 28, 2023
@Gobot1234
Copy link
Contributor

Gobot1234 commented Jun 17, 2023

Just adding a smidge to this it'd also be nice for it to work for functions as well doesn't matter I've seen the PR now

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants