openrewrite / rewrite-python

OpenRewrite recipes for Python.
Apache License 2.0
12 stars 5 forks source link
openrewrite openrewrite-recipes

rewrite-python

This repository is a work-in-progress implementation of Rewrite Python language support.

Implementation Progress

This is largely based on the Python grammar specification.

Resources

Statements

Element Status Example Mapping Notes Limitations
File
Simple Statement List
a = 1; b=a*2; print(b)
Function Definition
If Statement
Class Definition Implemented as J.ClassDeclaration. Base classes are stored in implementings.
With Statement Implemented as J.Try with a non-empty resources list.
For Statement
Try Statement
While Statement
Match Statement
Except Statement
Assignment Statement
Augment-Assignment Unsupported: //, **, %, @.
Return Statement
return x
Import Statement
from . import foo
Implemented as J.Import, with GroupedStatement markers.
Raise Statement
Pass Statement
pass
Implemented as Py.PassStatement.
Delete Statement
del x, y
Implemented as Py.DelStatement.
Yield Statement
Assert Statement
assert x, y
Implemented as Py.Assert.
Break Statement
break
Continue Statement
continue
Global Statement
global x
Implemented as Py.VariableScopeStatement.
Nonlocal Statement
nonlocal x
Implemented as Py.VariableScopeStatement.
Decorators Implemented as J.Annotation. Does not support arbitrary expressions (PEP 614).
Type Comments
Numeric Literal
String Literal
Boolean Literal
None Literal
None
Implemented as Java null.
List Literal
[1, 2, 3]
Implemented as __builtins__.list call.
Set Literal
{1, 2, 3}
Implemented as __builtins__.set call.
Dict Literal
{1: 2, 3: 4}
Tuple Literal
(1, 2, 3)
Implemented as __builtins__.tuple call.
List Comprehension
[x for x in xs]
Set Comprehension
{x for x in xs}
Dict Comprehension
{x:x for x in xs}
Generator Comprehension
(x for x in xs)
Yield Expression
yield from x
Implemented as Py.YieldExpression.
Await Expression
await x
Implemented as Py.AwaitExpression.
Bitwise Operators
Arithmetic Operators
Comparison Operators Non-Java comparisons are implemented using desugared magic methods (e.g. __eq__).
Slices Implemented using a desugared call to __builtins__.slice.
Lambda Expressions
Call Expressions
print(42)
Invocation of arbitrary expressions is implemented using desugared __call__.
Attribute Access Implemented as J.FieldAccess.
Comments Implemented as PyComment.