desugar
Unravelling Python source code.
Unravelled syntax
-
obj.attr
➠builtins.getattr(obj, "attr")
(includingobject.__getattribute__()
) -
a + b
➠operator.add(a, b)
-
a - b
➠operator.sub(a, b)
-
a * b
➠operator.mul(a, b)
-
a @ b
➠operator.matmul(a, b)
-
a / b
➠operator.truediv(a, b)
-
a // b
➠operator.floordiv(a, b)
-
a % b
➠operator.mod(a, b)
-
a ** b
➠operator.pow(a, b)
-
a << b
➠operator.lshift(a, b)
-
a >> b
➠operator.rshift(a, b)
-
a & b
➠operator.and_(a, b)
-
a ^ b
➠operator.xor(a, b)
-
a | b
➠operator.or_(a, b)
Syntax to (potentially) unravel
Keywords
Taken from the keyword
module.
-
False
-
True
-
None
-
and
-
or
-
assert
-
await
-
break
-
continue
-
pass
-
class
-
def
-
async
-
lambda
-
if
-
elif
-
else
-
for
-
while
-
with
-
try
-
except
-
finally
-
global
-
nonlocal
-
import
-
from
-
as
-
del
-
in
-
is
-
not
-
raise
-
return
-
yield
Tokens
Taken from the token
module.
-
~
-
-
(unary) -
+
(unary) -
+=
-
-=
-
*=
-
@=
-
/=
-
//=
-
%=
-
**=
-
<<=
-
>>=
-
&=
-
^=
-
|=
-
==
-
!=
-
<
-
<=
-
>
-
>=
-
=
-
:=
-
[]
-
{}
-
()
-
,
-
:
-
;
-
->
-
...
Literals
The list below ignores literals which are represented via syntax above.
For instance, lists are left off as they are represented by []
tokens.
- Bytes (
b
,r
) - Strings (
u
,f
,r
; single line, multi-line) - Integers (base-10,
b
,o
,x
) - Floats (point,
e
) - Complex/imaginary numbers