Commit graph

74 commits

Author SHA1 Message Date
martin
de5635394b
fix: circular import error (#1406)
* fix: circular import error
2025-09-25 23:44:58 -04:00
martin
9542fc3882
remove entry points to pure parser (#1375)
* rm: ci

* rm: entry point

* fix: tests

* fix: remove combine step from ci

* linter fixes

* omit the _parser

* fix newlines

* fix: remove optional

* fix: linter

---------

Co-authored-by: thereversiblewheel <martin.li@uwaterloo.ca>
2025-07-30 16:27:20 +00:00
Zsolt Dollenstein
52acdf4163
cli: Instantiate Codemods per file (#1334)
Instead of sharing instances of a Codemod across many files, this PR allows passing in a Codemod class to `parallel_exec_transform_with_prettyprint` which will then instantiate the Codemod for each file.  `tool._codemod_impl` now starts using this API.

The old behavior is deprecated, because sharing codemod instances across files is a surprising behavior, and causes hard-to-diagnose bugs when a Codemod keeps track of its state via instance variables.
2025-05-25 09:23:10 +01:00
Jia Chen
e20e757159
Remove uses of # pyre-placeholder-stub (#1174) 2024-07-20 09:04:25 +01:00
Zsolt Dollenstein
8b97600fb3
fix various Match statement visitation errors (#1161)
Fixes #1160.

This PR also

- fixes `whitespace_before_colon` being swallowed during visitation on `MatchCase`s
- adds a new type of roundtrip test that catches issues of this class: the test applies a noop transformer to exercise the visitation API and compares the result with the original source.
- adds a few more cases to the match fixture
2024-06-12 17:29:25 +01:00
Zsolt Dollenstein
db696e6348
fix: don't reset context.scratch between files (#1151)
#453 fixed scratch leaking between files by setting it to empty, but that drops all the scratch space that was set up before the codemod runs (e.g. in the transformer's constructor)

This PR improves the fix by preserving the initial scratch.
2024-05-21 15:52:49 -04:00
martin
71b0a1288b
Implement Type Defaults for Type Parameters (PEP 696) (#1141)
Co-authored-by: thereversiblewheel <martin.li@uwaterloo.ca>
2024-05-20 11:26:38 -04:00
zaicruvoir1rominet
6bbc69316b
Add the ability to dump CST to .dot (graphviz) files (#1147)
* Make the nodes fields filtering process - from libcst.tool - public, so that other libraries may provide their own custom representation of LibCST graphs.

* Create functions to access & filter CST-node fields (with appropriate docstrings & tests), in libcst.helpers

* Add new CST-node fields functions to helpers documentation.
2024-05-20 11:25:13 -04:00
Zsolt Dollenstein
2ffca10845
remove typing dependencies (#1126)
Summary:
This PR removes the `typing_extensions` and `typing_inspect` dependencies as we can now rely on the built-in `typing` module since Python 3.9.

Test Plan:
existing tests
2024-04-03 19:50:14 +01:00
Zsolt Dollenstein
55f3e34dfc
Add roundtrip tests from Python (#1098)
Our current roundtrip tests only excerise the Rust codepaths. This PR runs the same roundtrip scenarios but from Python.
2024-02-02 20:50:07 +00:00
Zsolt Dollenstein
738dc2f893
Upgrade pyre (#1032)
* Upgrade pyre

* regen fixtures
2023-10-02 09:43:17 -07:00
Zsolt Dollenstein
9286446f88
PEP 695 - Type Parameter Syntax (#1004)
This PR adds support for parsing and representing Type Parameters and Type Aliases as specified by PEP 695. What's missing are the scope rules, to be implemented in a future PR.

Notable (user visible) changes:

- new `TypeAlias` CST node, which is a `SmallStatement`
- new CST nodes to represent TypeVarLikes: `TypeVar`, `TypeVarTuple`, `ParamSpec`
- new helper CST nodes:  `TypeParameters` to serve as a container for multiple TypeVarLikes, and `TypeParam` which is a single item in a `TypeParameters` (owning the separating comma)
- extended `FunctionDef` and `ClassDef` with an optional `type_parameters` field, as well as `whitespace_after_type_parameters` to own the extra whitespace between type parameters and the following token
  - these new fields are added after all others to avoid breaking callers passing in fields as positional arguments
- in `FunctionDef` and `ClassDef`, `whitespace_after_name` now owns the whitespace before the type parameters if they exist
2023-08-28 22:07:22 +01:00
Sergii Dymchenko
0f7766f451
Don't gather dirs ending .py (#994) 2023-08-26 10:54:32 +01:00
Amethyst Reese
6a7b82e2b6 PEP 621 + hatch to run tests/lint/etc
Moves PEP 621 metadata from `setup.py` and `requirements*.txt` into the
`[project]` table of `pyproject.toml`. This enables using hatch as a
task runner for the project, where previously one would need to remember
a bunch of different commands, or repeatedly consult the readme's
developer guide to find all of the relevant commands.

This creates the following hatch commands:

- docs
- fixtures
- format
- lint
- test
- typecheck

It also updates all of the github actions workflows to use the
appropriate hatch commands, and the readme's developer guide, so that
there is only one source of truth for what constitutes running tests.

The "test" workflows now drop the matrix distinction between "pure" or
"native", and run tests in both modes from a single build.

ghstack-source-id: 8834da7825
Pull Request resolved: https://github.com/Instagram/LibCST/pull/893
2023-03-14 19:37:41 -07:00
Amethyst Reese
d94687e378
Script to regenerate test fixtures (#872)
Upgrading Pyre requires updating test fixtures with any upstream changes
to Pyre's query results for the `simple_class.py` fixture.

This adds a new `scripts/` directory to the repo, with a script to
regenerate test fixtures. The script regenerates the cache data fixture,
and updates the `TypeInferenceProvider` tests to use `assertDictEqual`
and helpful error messages for better behavior in future mismatches.

This also includes a slight bump to Pyre 0.9.10 to fix install issues on
Apple Silicon M1 Macs, and regenerated fixtures using the script above.
2023-02-22 12:35:23 -08:00
Arie Bovenberg
bd5ede7953
add slots to base classes, @add_slots takes bases into account (#605)
* add slots to base classes, @add_slots takes bases into account
* state changes in apache 2.0 licensed add_slots
2022-01-16 14:14:32 +00:00
Zsolt Dollenstein
d9a1dc8473
Fix all type errors (#579)
* bump pyre version
* make sure CI-pyre uses working copy
* remove unused pyre suppressions
* suppress invalid decorations
* fix undefined attributes
* fix missing return annotations
* fix tuple concatenation issues
* add native stubs
* fix invalid typing of **kwargs in test_apply_type_annotations
* only install pyre on non-windows
* update test fixture to reflect changes in recent pyre versions
* suppress errors related to mismatched positions
2022-01-05 18:13:01 +00:00
Zsolt Dollenstein
c44ff0500b
Fix license headers (#560)
* Facebook -> Meta

* remove year from doc copyright
2021-12-28 11:55:18 +00:00
John Reese
10c3aa09a7
Upgrade to µsort 1.0.0rc1, and apply formatting changes (#565)
* Upgrade to usort==1.0.0rc1

* Apply sorting changes from usort 1.0.0rc1

* reapply codegen

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2021-12-21 14:55:04 -08:00
Zsolt Dollenstein
c02de9b718
Implement a Python PEG parser in Rust (#566)
This massive PR implements an alternative Python parser that will allow LibCST to parse Python 3.10's new grammar features. The parser is implemented in Rust, but it's turned off by default through the `LIBCST_PARSER_TYPE` environment variable. Set it to `native` to enable. The PR also enables new CI steps that test just the Rust parser, as well as steps that produce binary wheels for a variety of CPython versions and platforms.

Note: this PR aims to be roughly feature-equivalent to the main branch, so it doesn't include new 3.10 syntax features. That will be addressed as a follow-up PR.

The new parser is implemented in the `native/` directory, and is organized into two rust crates: `libcst_derive` contains some macros to facilitate various features of CST nodes, and `libcst` contains the `parser` itself (including the Python grammar), a `tokenizer` implementation by @bgw, and a very basic representation of CST `nodes`. Parsing is done by
1. **tokenizing** the input utf-8 string (bytes are not supported at the Rust layer, they are converted to utf-8 strings by the python wrapper)
2. running the **PEG parser** on the tokenized input, which also captures certain anchor tokens in the resulting syntax tree
3. using the anchor tokens to **inflate** the syntax tree into a proper CST

Co-authored-by: Benjamin Woodruff <github@benjam.info>
2021-12-21 18:14:39 +00:00
Rodrigo Zhou
683731b1e1
Fix pyre command for type inference provider (#523)
* Fix pyre command for type inference provider

* fix integration test

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2021-09-16 17:59:24 +01:00
Steven Troxler
69156c7775
Bump pyre-check to latest version (#516)
The current version of the pyre query api requires a running
watchman server, which has to be started independently.
2021-09-07 12:08:46 +01:00
Steven Troxler
5e1e3fe970
The ufmt tool combines usort and black with a consistent wrapper, (#515)
which ensures we won't have inconsistent black-vs-isort errors
going forward. We can always format by running `ufmt format .`
at the root, and check with `ufmt check .` in our CI actions.
2021-08-25 20:39:29 -04:00
Lisa Roach
e759ca8290
Fix leaking processes from TypeInferenceProvider (#474)
* Switches to subprocess.run.

* Updates cmd to avoid string escaping.
2021-04-02 20:08:54 +01:00
Bruno Alla
f78de1b786
Fix context.scratch leaking across files (#453) 2021-01-27 10:02:17 +00:00
Germán Méndez Bravo
21d37b94b2
Support string annotations for type aliases (#401) 2020-10-12 11:12:28 -07:00
Jimmy Lai
7ca738bf39
Upgrade dev tools (Black/Flake8/isort) and read install requirements from requirements.txt (#380)
* Read install requirements from requirements.txt

* read extras_require from requirements-dev.txt

* add requirements-dev.txt to MANIFEST.in

* apply fixes for new version of Black and Flake8

* don't upgrade Pyre

* re-format
2020-08-31 10:44:55 -07:00
jimmylai
c023fa7c4c
[typing] enable Pyre strict mode by default (#313)
Co-authored-by: Jimmy Lai <jimmylai@fb.com>
2020-06-12 18:24:18 -07:00
Jimmy Lai
dee174d5f8 [typing] add missing type annotations 2020-03-19 07:41:19 -07:00
Jennifer Taylor
6a9fd40413 Upgrade Pyre to 0.0.41 to hopefully resolve issue with installation. 2020-01-28 09:28:15 -08:00
Jennifer Taylor
6eb6ec7b1d Add posonly parameter support to Parameters node.
This is part one of a two-part change to support the posonly param indicator "/".
2020-01-15 11:18:12 -08:00
Jimmy Lai
78f0e13c48 Upgrade Pyre to 0.0.39 2020-01-09 11:06:40 -08:00
Jennifer Taylor
91387f5f2f Remove deprecated default_params attribute. 2020-01-08 17:18:41 -08:00
Jennifer Taylor
40e19ac457 Remove deprecated ExtSlice. 2020-01-08 17:18:19 -08:00
Jimmy Lai
b6ec177933 Use Pyre strict mode in Pyre test suite 2020-01-02 10:08:15 -08:00
Jimmy Lai
9b7219b1a9 run pyre codegen in CI 2020-01-02 10:08:00 -08:00
Jimmy Lai
f6ecf67bb9 move type inference related logic to TypeInferenceProvider 2019-12-28 20:51:29 -08:00
Jimmy Lai
9b84df7feb add FullRepoManager 2019-12-28 20:51:29 -08:00
Jimmy Lai
88267c8de1 rebase onto pyre_test_suite 2019-12-27 12:35:53 -08:00
Jimmy Lai
7a17cac2cf remove unused parentheses 2019-12-27 11:40:15 -08:00
Jimmy Lai
a67dc670b8 upgrade Pyre to 0.0.38 2019-12-23 23:52:40 -08:00
Jimmy Lai
c4891761b2 Merge branch 'master' of github.com:Instagram/LibCST into pyre_test_suite 2019-12-20 13:02:28 -08:00
Jimmy Lai
779f20d358 add test suite for pyre regression test 2019-12-17 09:28:57 -08:00
Zach Hammer
20a73807c1 Fix black formatting 2019-12-06 10:58:50 -08:00
Zach Hammer
e211bea16c Fix inconsistent type override errors
It seems that @mark_no_op was not correctly preserving type signatures
in pyre previous to this change. Preserving type signatures in the
decorator caused some pyre errors in tests where visitors are defined
that don't share the same arg names as their parent.
2019-12-06 10:58:50 -08:00
Jennifer Taylor
64e298b2cc Fix batchable visitor not calling attribute visitors. 2019-11-14 11:28:15 -08:00
Jennifer Taylor
f492103ad2 More explicit fuzz testing environments.
Let's split from just fuzzing on the default python to having a separate fuzzer for each version of python we support. This should help us catch any issues should they arise in differences with grammars across releases. Right now we're fuzz-clean as well, so I also bumped up the thresholds to stress test LibCST more. I anticipate that this will be useful when we begin work on 3.8 support.
2019-10-22 17:24:03 -07:00
Jennifer Taylor
9522da0de2 Skip fuzz testing code with form feeds, due to incompatibility with LibCST. 2019-10-21 13:16:35 -07:00
Jennifer Taylor
fa646790df Fix expression fuzzing by making it only compare if LibCST can parse. 2019-10-21 13:16:35 -07:00
Jennifer Taylor
48ba3b0849 Remove parsing Subscript slice directly into Index/Slice.
This makes sure we always wrap elements in a SubscriptElement, even when there
is only one element. This makes things more regular while still being backwards
compatible with existing creation. The meat of this is in two halves, which can't
be split due to not wanting to break the build between commits. The first half
is just the changes to the parser and updates to tests. This includes a test to
be sure we can still render code that uses old construction types. The second half
is changes to codegen which made assumptions about `Subscript` and demonstrates
the need to make this change in the first place. This includes a fix to
`CSTNode.with_deep_changes` type to make it more correct and also more usable in
transforms without additional type assertions.
2019-10-18 13:40:10 -07:00