Skip to content

Replace libcst with stdlib AST + tokenize - #169

Merged
AlexWaygood merged 9 commits into
mainfrom
libcst-no-deps
Jun 9, 2026
Merged

Replace libcst with stdlib AST + tokenize#169
AlexWaygood merged 9 commits into
mainfrom
libcst-no-deps

Conversation

@AlexWaygood

@AlexWaygood AlexWaygood commented Jun 8, 2026

Copy link
Copy Markdown
Member

Replace libcst with a handwritten codemod implementation using the stdlib AST + tokenize modules.

libcst doesn't support Python 3.15 yet, and it may be months until it does. I don't really know what the maintenance story is over there these days, and I don't want docstring-adder's Python-version support to be tied to a Meta repo. Using stdlib AST + tokenize adds less complexity than I would've assumed; it actually allows us to simplify the implementation in a number of places.

I also explored using the asttokens library (see #166). It doesn't simplify things meaningfully over this approach, however, and I don't like the library's approach of monkeypatching tokens onto AST nodes. It makes it very hard to use the library in an app like this that uses strict typing. I'm also not sure what the maintenance story is over in that repo: there haven't been any commits in half a year; and the type hints are extremely antiquated (they can't be understood by ty).

Closes #165

@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

1 similar comment
@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

1 similar comment
@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

This comment has been minimized.

@astral-sh-bot

astral-sh-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

This change has no effect on the docstrings that would be added to typeshed. 🤖🎉

@AlexWaygood
AlexWaygood marked this pull request as ready for review June 9, 2026 13:25
@AlexWaygood
AlexWaygood merged commit 93e036b into main Jun 9, 2026
@AlexWaygood
AlexWaygood deleted the libcst-no-deps branch June 9, 2026 13:26
AlexWaygood added a commit to astral-sh/ruff that referenced this pull request Jun 9, 2026
## Summary

Pulls in astral-sh/docstring-adder#169, so that
we have a version of docstring-adder that supports 3.15. This enables us
to add docstrings for the new-in-3.15 branches in typeshed.

I also switched us to temporarily use a version of Black from git,
because I'm too impatient to wait for a release that includes
psf/black@f665703.

## Test Plan

CI on docstring-adder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for 3.15

1 participant