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

typed-ast: fix get_docstring, allow buffer #9019

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions stubs/typed-ast/typed_ast/ast27.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import ReadableBuffer
from collections.abc import Iterator
from typing import Any
from typing_extensions import TypeAlias
Expand All @@ -9,11 +10,11 @@ class NodeVisitor:
class NodeTransformer(NodeVisitor):
def generic_visit(self, node: AST) -> None: ...

def parse(source: str | bytes, filename: str | bytes = ..., mode: str = ...) -> AST: ...
def parse(source: str | ReadableBuffer, filename: str | ReadableBuffer = ..., mode: str = ...) -> AST: ...
def copy_location(new_node: AST, old_node: AST) -> AST: ...
def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ...
def fix_missing_locations(node: AST) -> AST: ...
def get_docstring(node: AST, clean: bool = ...) -> bytes | None: ...
def get_docstring(node: AST, clean: bool = ...) -> str | bytes | None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused about how this could be bytes, but then I remembered Python 2.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ast27.get_docstring(ast27.parse("""def f(): 'hi'""").body[0]) does crash at runtime (but it works with clean=False)

def increment_lineno(node: AST, n: int = ...) -> AST: ...
def iter_child_nodes(node: AST) -> Iterator[AST]: ...
def iter_fields(node: AST) -> Iterator[tuple[str, Any]]: ...
Expand Down
5 changes: 4 additions & 1 deletion stubs/typed-ast/typed_ast/ast3.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import ReadableBuffer
from collections.abc import Iterator
from typing import Any
from typing_extensions import TypeAlias
Expand All @@ -9,7 +10,9 @@ class NodeVisitor:
class NodeTransformer(NodeVisitor):
def generic_visit(self, node: AST) -> None: ...

def parse(source: str | bytes, filename: str | bytes = ..., mode: str = ..., feature_version: int = ...) -> AST: ...
def parse(
source: str | ReadableBuffer, filename: str | ReadableBuffer = ..., mode: str = ..., feature_version: int = ...
) -> AST: ...
def copy_location(new_node: AST, old_node: AST) -> AST: ...
def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ...
def fix_missing_locations(node: AST) -> AST: ...
Expand Down