Skip to content

Releases: yunline/Oneliner-Py

1.2.0

16 Dec 14:28
Compare
Choose a tag to compare

New Features

"chain_call" wrapper

Consider a class with __del__ method specified like

class B:
    def __del__(self):
        print(123456)

Do folowing operations

b = B()
b = None
print(654321)

At line 2, instance B() is released, __del__ method is called, 123456 is printed. Then, at line 3, 654321 is printed.

With the original "list" wrapper, we get following converted code

[b:=B(),b:=None,print(654321)]

We can find, even though b is set to None, the B() is not deleted until the whole list is released. That means, this piece of code will print 654321 first, then 123456. The behavior is inconsistent with the original code.

So the "chain_call" wrapper is born

(__ol_run:=lambda _:__ol_run)(b:=B())(b:=None)(print(654321))

The value of each expression in the wrapper will be destroyed instantly after the evaluation of the expression. The delayed-delete wont happen any more. The code prints 123456 then 654321 now.

By default, the "chain_call" wrapper will be selected. To select the old "list" wrapper, add -Cexpr_wrapper=list to the command line.

“short_circuit” style if-elif-else

For an if-elif-elsecode

if b:
    print("1")
elif c:
    print("2")
else:
    print("3")

Using the if-expressions, we get the oneliner

print('1') if b else print('2') if c else print('3')

Using the short-circuit expessions, we will get an equivalent oneliner that is much harder to read.

b and (print('1') or 1) or c and (print('2') or 1) or print('3')

For a if statement without elif or else, the output will be simplified

# original
if b:
    print("hello")

# oneliner
b and print('hello')

To use the "short circuit" style if, add -Cif_style=short_circuit to the command line

Command Line Changes

A new -C argument is added for setting configs of oneliner convertion.
The --unparser <unparser_name> argument is deprecated, use -Cunparser=<unparser_name> instead.
The --unparser argument will be removed in 1.3.0

Code Quality

mypy checker

In 1.2.0, Oneliner-Py uses mypy to check the code typing.
With the help of mypy, a lot of typing problems have been found and fixed.

Tests for expr_unparse

A bunch of tests have been added for our own unparser expr_unparse. Now the test coverage of expr_unparse.py is 100%. While writing the test, a lot of bugs in expr_unparse have been found and fixed.

1.1.0

03 Dec 03:38
Compare
Choose a tag to compare

Bug fix

  • Fixed the conversion of list comprehension in a function namespace

New feature

  • A new unparser is added for a more compact output code format
  • Argument --unparser is added to the commandline for choosing the unparser
  • Argument -v and --version are added for checking the version of Oneliner-Py

Oneliner-Py 1.0.0

11 Sep 04:20
Compare
Choose a tag to compare

First Release 🎉🎉🎉