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)
a += b
➠a = operator.__iadd__(a, b)
a -= b
➠a = operator.__isub__(a, b)
a *= b
➠a = operator.__imul__(a, b)
a @= b
➠a = operator.__imatmul__(a, b)
a /= b
➠a = operator.__itruediv__(a, b)
a //= b
➠a = operator.__ifloordiv__(a, b)
a %= b
➠a = operator.__imod__(a, b)
a **= b
➠a = operator.__ipow__(a, b)
a <<= b
➠a = operator.__ilshift__(a, b)
a >>= b
➠a = operator.__irshift__(a, b)
a &= b
➠a = operator.__iand__(a, b)
a ^= b
➠a = operator.__ixor__(a, b)
a |= b
➠a = operator.__ior__(a, b)
~ a
➠operator.__invert__(a)
- a
➠operator.__neg__(a)
+ a
➠operator.__pos__(a)
a == b
➠operator.__eq__(a, b)
(includingobject.__eq__()
)a != b
➠operator.__ne__(a, b)
(includingobject.__ne__()
)a < b
➠operator.__lt__(a, b)
a <= b
➠operator.__le__(a, b)
a > b
➠operator.__gt__(a, b)
a >= b
➠operator.__ge__(a, b)
Syntax to (potentially) unravel
Keywords
Taken from the keyword
module.
-
None
-
False
~ -
True
~ -
and
~ -
or
~ -
assert
* -
await
~ -
break
-
continue
-
pass
* -
def
-
class
* -
async
~ -
lambda
~ -
if
-
elif
-
else
-
while
-
for
* -
with
* -
try
-
except
-
finally
-
global
-
nonlocal
-
import
* -
from
* -
as
-
del
-
not
-
in
* -
is
* -
raise
-
return
-
yield
Tokens
Taken from the token
module.
-
=
-
:=
-
[]
* -
{}
* -
()
-
,
-
:
-
;
* -
->
* -
...
*
Literals
The list below ignores literals which are represented via syntax above.
For instance, lists are ignored 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