desugar

Re-implement the parts of Python that allow removing its syntactic sugar.


License
MIT
Install
pip install desugar==0

Documentation

desugar

Unravelling Python source code.

Unravelled syntax

  1. obj.attr âž  builtins.getattr(obj, "attr") (including object.__getattribute__())
  2. a + b âž  operator.add(a, b)
  3. a - b âž  operator.sub(a, b)
  4. a * b âž  operator.mul(a, b)
  5. a @ b âž  operator.matmul(a, b)
  6. a / b âž  operator.truediv(a, b)
  7. a // b âž  operator.floordiv(a, b)
  8. a % b âž  operator.mod(a, b)
  9. a ** b âž  operator.pow(a, b)
  10. a << b âž  operator.lshift(a, b)
  11. a >> b âž  operator.rshift(a, b)
  12. a & b âž  operator.and_(a, b)
  13. a ^ b âž  operator.xor(a, b)
  14. a | b âž  operator.or_(a, b)

Syntax to (potentially) unravel

Keywords

Taken from the keyword module.

  1. False

  2. True

  3. None

  4. and

  5. or

  6. assert

  7. await

  8. break

  9. continue

  10. pass

  11. class

  12. def

  13. async

  14. lambda

  15. if

  16. elif

  17. else

  18. for

  19. while

  20. with

  21. try

  22. except

  23. finally

  24. global

  25. nonlocal

  26. import

  27. from

  28. as

  29. del

  30. in

  31. is

  32. not

  33. raise

  34. return

  35. yield

Tokens

Taken from the token module.

  1. ~

  2. - (unary)

  3. + (unary)

  4. +=

  5. -=

  6. *=

  7. @=

  8. /=

  9. //=

  10. %=

  11. **=

  12. <<=

  13. >>=

  14. &=

  15. ^=

  16. |=

  17. ==

  18. !=

  19. <

  20. <=

  21. >

  22. >=

  23. =

  24. :=

  25. []

  26. {}

  27. ()

  28. ,

  29. :

  30. ;

  31. ->

  32. ...

Literals

The list below ignores literals which are represented via syntax above. For instance, lists are left off as they are represented by [] tokens.

  1. Bytes (b, r)
  2. Strings (u, f, r; single line, multi-line)
  3. Integers (base-10, b, o, x)
  4. Floats (point, e)
  5. Complex/imaginary numbers