@@ -138,80 +138,80 @@ in a pyproject.toml `[tool.strip-python3]` or setup.cfg `[strip-python3]` sectio
138138The names are the same as the commandline options, just without a leading "--".
139139Use "--show" and "--show -v" for details of selected settings.
140140
141- ## define-print-function
141+ ## -- define-print-function
142142
143143If ` print() ` is used then ` from __future__ import print_function ` is added
144144if python2 compatibility is requested. (see [ doc] ( doc/define-print-function.md ) )
145145
146- ## define-float-division
146+ ## -- define-float-division
147147
148148If ` / ` is used then ` from __future__ import division ` is added
149149if python2 compatibility is requested. (see [ doc] ( doc/define-float-division.md ) )
150150
151- ## define-absolute-import
151+ ## -- define-absolute-import
152152
153153If ` .localtypes ` is used then ` from __future__ import absolute_import ` is added
154154if python2 compatibility is requested. (see [ doc] ( doc/define-absolute-import.md ) )
155155
156- ## define-basestring
156+ ## -- define-basestring
157157
158158If ` isinstance(x, str) ` is used then each is replaced by ` isinstance(x, basestring) `
159159if python2 compatibility is requested. It does also import ` basestring = str ` for
160160python3 versions. (see [ doc] ( doc/define-basestring.md ) )
161161
162- ## define-range
162+ ## -- define-range
163163
164164If ` range(x) ` is used then ` range = xrange ` is defined for python2 versions
165165if python2 compatibility is required. (see [ doc] ( doc/define-range.md ) )
166166
167- ## define-callable
167+ ## -- define-callable
168168
169169If ` callable(x) ` is used then a ` def callable ` boilerplate is added for python3
170170versions where it was not predefined, which only in 3.0 and 3.1 (see [ doc] ( doc/define-callable.md ) )
171171
172- ## datetime-fromisoformat
172+ ## -- datetime-fromisoformat
173173
174174If ` datetime.datetime.fromisoformat ` is used then it is replaced by ` datetime_fromisodate `
175175with boilerplate code if python2 or python3 older than 3.7. (see [ doc] ( doc/datetime-fromisoformat.md ) )
176176
177- ## subprocess-run
177+ ## -- subprocess-run
178178
179179If ` subprocess.run ` is used then it is replaced by ` subprocess_run `
180180with boilerplate code if python2 or python3 older than 3.5. (see [ doc] ( doc/subprocess-run.md ) )
181181
182- ## time-monotonic
182+ ## -- time-monotonic
183183
184184If ` time.monotonic ` is used then it is replaced by ` time_monotonic `
185185with boilerplate code based on ` time.time ` . This is needed for
186186python2 or python3 older than 3.3. (see [ doc] ( doc/time-monotonic.md ) )
187187
188- ## import-pathlib2
188+ ## -- import-pathlib2
189189
190190If ` import pathlib ` is used then it is replaced by ` import pathlib2 `
191191if python2 compatiblity is requested. Pathlib exists since python 3.3
192192but there is a backport available (to be installed seperately)
193193
194- ## import-backports-zoneinfo
194+ ## -- import-backports-zoneinfo
195195
196196If ` import zoneinfo ` is used then it is replaced by ` from backports import zoneinfo `
197197if python3 compatiblity is requested before python 3.9 (backport requires atleast 3.6)
198198
199- ## import-toml
199+ ## -- import-toml
200200
201201If ` import tomllib ` is used then it is replaced by ` import toml `
202202if compatiblity with python older than 3.11 is requested. The
203203external toml package (to be installed seperately) did exist
204204before and was integrated into the standard lib.
205205
206- ## catch-ioerror and catch-select-error
206+ ## -- catch-ioerror and -- catch-select-error
207207
208208if ` except OSError ` is used then it gets extended to ` except (OSError, IOError) ` .
209209if python3 compatibility is requested before python 3.3 (having PEP3151)
210210
211211On ` import select ` it gets extended to ` except (OSError, select.error) ` .
212212So for python 3.3 that results in ` except (OSError, IOError, select.error) ` .
213213
214- ## replace-fstring
214+ ## -- replace-fstring
215215
216216If ` F"string {part}" ` is used then it is replaced by ` "string {}".format(part) `
217217if python2 compatibility requested, as well as python3 older than 3.5.
@@ -223,15 +223,15 @@ you can write `F"string {len(part):4n}: {part}"` which gets expanded to:
223223
224224See [ doc for details] ( doc/replace-fstring.md ) and ` --fstring-from-var-locals ` .
225225
226- ## replace-namedtuple-class
226+ ## -- replace-namedtuple-class
227227
228228If ` class Result(NamedTuple) ` is used then it is replaced by ` Result = namedtuple("Result",[]) `
229229if python2 compatibility requested, as well as python3 older than 3.6. (see [ doc] ( doc/replace-namedtuple-class.md ) )
230230
231231They pyi typehints file retains the NamedTuple definition. An exception is thrown if
232232the NamedTuple class contains non-variable definitions (like method functions).
233233
234- ## replace-walrus-operator
234+ ## -- replace-walrus-operator
235235
236236If ` if x := fu(): pass ` is used then it is replaced by ` x = fu() ` followed
237237by ` if x: pass ` if python2 compatibility requested, as well as python3 older than 3.8.
@@ -248,50 +248,50 @@ When using `while (x:= fu()) != "end": print(x)` it gets expanded to
248248Currently only if-walrus and while-walrus are supported. Only a direct
249249assignment or compare/binop is supported. See [ doc for details] ( doc/replace-walrus-operator.md ) .
250250
251- ## replace-annotated-typing
251+ ## -- replace-annotated-typing
252252
253253If ` var: Annotated[int, Field(gt=0)] ` is used then it is replaced by ` var: int `
254254if python2 compatibility requested, as well as python3 older than 3.9.
255255(see [ doc for details] ( doc/replace-annotated-typing.md ) )
256256
257- ## replace-builtin-typing
257+ ## -- replace-builtin-typing
258258
259259If ` var: list[int] ` is used then it is replaced by ` var: List[int] `
260260if python2 compatibility requested, as well as python3 older than 3.9.
261261(see [ doc for details] ( doc/replace-builtin-typing.md ) )
262262
263- ## replace-union-typing
263+ ## -- replace-union-typing
264264
265265If ` var: int|str ` is used then it is replaced by ` var: Union[int, str] `
266266if python2 compatibility requested, as well as python3 older than 3.10.
267267It does also replace ` var: int|None ` by ` var: Optional[int] `
268268(see [ doc for details] ( doc/replace-builtin-typing.md ) )
269269
270- ## replace-self-typing
270+ ## -- replace-self-typing
271271
272272If ` param: Self ` is used then it is replaced by ` param: SelfB `
273273if python2 compatibility requested, as well as python3 older than 3.11.
274274It does declare a ` SelfB = TypeVar("SelfB", bound="B") ` as suggested
275275in PEP 673, and it works for the return type of a class method as well.
276276(see [ doc for details] ( doc/replace-self-typing.md ) )
277277
278- ## remove-keywordsonly
278+ ## -- remove-keywordsonly
279279
280280The keywordsonly syntax became available in python 3.0, so it need to be
281281removed for python2 (see [ doc] ( doc/remove-positionalonly.md ) )
282282
283283
284- ## remove-positionalonly
284+ ## -- remove-positionalonly
285285
286286The postionalonly syntax became available in python 3.8, so it need to be
287287removed for python2 and python3 older than 3.8 (see [ doc] ( doc/remove-positionalonly.md ) )
288288
289- ## remove-var-typehints
289+ ## -- remove-var-typehints
290290
291291The var typehints became available in python 3.6, so they need to be
292292removed for older python3 (or python2)
293293
294- ## remove-typehints
294+ ## -- remove-typehints
295295
296296The function annotations became available in python 3.0, so they need to
297297be removed for python2. Note that the typehints syntax became available
@@ -306,12 +306,12 @@ The `"*.pyi"` file generation needs to be requested with the "--pyi" commandline
306306The transformations are automatically selected by the minimum target python version
307307that is given by --pyi-version=3.8 (which is the default).
308308
309- ## remove-positional-pyi
309+ ## -- remove-positional-pyi
310310
311311The postionalonly syntax became available in python 3.8, so it need to be
312312removed for python3 compatiblity older than 3.8.
313313
314- ## remove-typeddict-pyi
314+ ## -- remove-typeddict-pyi
315315
316316The TypedDict definition became available in python 3.8, so it need to be
317317removed for python3 compatiblity older than 3.8.
@@ -344,6 +344,44 @@ after transformations.
344344
345345If no ` *.pyi ` file is wanted then disable it with "--no-pyi" again.
346346
347+ # Parser Variants
348+
349+ By default, ast_comments is used to parse/unparse the source tree. This is
350+ actually using the stdlib ast.parse adding comments by line number after
351+ the source code tree has been loaded, and it adds a visitComment to the
352+ stdlib.unparse that was introduced in Python 3.9. In some cases this
353+ scheme generates bad code - specifically, when block heads and expr
354+ statements are on the same line (` if true: return 1 ` ).
355+
356+ ## --no-comments
357+
358+ Disables the comment node handling for both parse and unparse. The python
359+ core maintainers ensure the output to be correct. The only comment being
360+ kept (or actually added) is the shebang in the first line of the python
361+ file.
362+
363+ ## --remove-comments
364+
365+ Disables loading the comments but still uses the new unparser.
366+
367+ # Upgrade transfomers
368+
369+ Most transformers look for newer python features to be replaced
370+ by older features being the same or similar enough. The transformer
371+ classes are able to upgrade source code to newer python features
372+ as well.
373+
374+
375+ ## --fstring-from-locals
376+
377+ Replace ` "{x} {y}".format(**locals()) ` to be ` F"{x} {y}" ` .
378+
379+ ## --fstring-from-var-locals
380+
381+ Adding on ` --fstring-from-locals ` the format may be not
382+ a literal string. ` x='{name}'; x.format(**locals()) `
383+ gets replaced here.
384+
347385# Development
348386
349387[ DEVGUIDE.MD] ( DEVGUIDE.MD ) for more infos.
0 commit comments