PEP758 removes the requirement for parentheses to surround exceptions
in except and except* expressions when 'as' is not present.
This pr implements support for parsing these types of statements
#1343
Adds support to parse t-strings
Couple things of note:
TemplatedString* is largely a copy of FormattedString*
Since clients operate of libcst objects I consider this this part of a public API - following the python grammar (where TStrings are distinct from FStrings) seems like a good way to avoid changes to the API in the future.
Within the tokenizer we reuse the fstring machinery
I consider this an implementation detail, fstrings and tstrings are (for now) identical, we can change this later without changes to the public api.
Since 2 -> we have a new FTStringType enum
We need to discriminate between f and t strings to know which token to return, a bit clumsy to use in my opinion - so looking for feedback here on how to improve this.
* generate Attribute nodes when applying type annotations
The old version generated an incorrect CST which
happened to work as long as you didn't do further processing.
* add a test
* add failing test
* fix issue
* fixes an issue with PositionProvider not working with case statement
* remove comments
---------
Co-authored-by: steve <steve@patreon.com>
* Keep old exception messages (avoid breaking-changes for users relying on exception messages)
* Move ``get_expected_str`` out of _exceptions.py, where it does not belong, to its own file in _parser/_parsing_check.py
From 3.14 onwards, we'll get `foo | bar` instead of `typing.Union[foo, bar]` as the annotation for union types (including optional). This PR prepares the codegen script for this.
This PR:
1. marks the `libcst.native` module as free-threading-compatible
2. replaces the use of ProcessPoolExecutor with ThreadPoolExecutor if free-threaded CPython is detected at runtime
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.
Instead of relying on `multiprocessing.Pool`, this PR replaces the implementation of `parallel_exec_transform_with_prettyprint` with `concurrent.futures.ProcessPoolExecutor`
When renaming `a.b` -> `c.d`, in imports like `import a.b as x` the as_name wasn't correctly removed even though references to `x` were renamed to `c.d`.
This PR makes the codemod remove the `x` asname in these cases.
* Add is_property check
Skip properties to prevent exceptions
* Delayed initialization of matchers
To support multiprocessing on Windows/macOS
Issue #1181
* Add a test for matcher decorators with multiprocessing
* Clean warnings for each file in comemod cli
* Fix ZeroDivisionError: float division by zero
When codemodding too fast
* Recreate CodemodContext for each file
Keep only context.metadata_manager
Remove wrapper from context defaults on each file
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
#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.
* 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.
* 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.
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
```
match a:
case 1, 2: pass
```
This is parsed correctly by the grammar, but the default values of `MatchList.lbracket` and `MatchList.rbracket` are inconsistent between Python and Rust, causing the above snippet to round-trip (from Python) to:
```
match a:
case [1, 2]: pass
```
Fixes#1096.
* Update test_fix_pyre_directives.py
refactor with fstring to format string to make code more Pythonic.
* Update test_fix_pyre_directives.py
refactor with fstring to format string to make code more Pythonic.
* Update test_fix_pyre_directives.py
refactor with fstring to format string to make code more Pythonic.
* Update test_fix_pyre_directives.py
refactor with fstring to format string to make code more Pythonic.
* Update test_fix_pyre_directives.py
refactor with chain constant value assignment to make code more Pythonic
* Update test_fix_pyre_directives.py
refactor with chain constant value assignment to make code more Pythonic