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

PyCode "Unparse": Added support for slice objects in subscriptions #11981

Merged
merged 12 commits into from
Feb 14, 2024
Next Next commit
Add visit_Slice in pycode.ast.py
  • Loading branch information
MatrixEditor committed Feb 14, 2024
commit 8372883e43cbe268f3ebb317de72fc178bf7535a
6 changes: 6 additions & 0 deletions sphinx/pycode/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,9 @@ def visit_Tuple(self, node: ast.Tuple) -> str:

def generic_visit(self, node: ast.AST) -> NoReturn:
raise NotImplementedError('Unable to parse %s object' % type(node).__name__)

def visit_Slice(self, node: ast.Slice) -> str:
picnixz marked this conversation as resolved.
Show resolved Hide resolved
start = self.visit(node.lower) if node.lower else ""
stop = self.visit(node.upper) if node.upper else ""
step = self.visit(node.step) if node.step else ""
return f"{start}:{stop}:{step}"