Created
August 19, 2022 10:44
-
-
Save westandskif/caaa7008cdeaa4694412e5f71a04ee9b to your computer and use it in GitHub Desktop.
codegen-medium-2022-08-19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from convtools import conversion as c | |
conversion = c.and_( | |
c.item(0) == b"abc", | |
c.item(2) > 15, | |
) | |
In [5]: converter = conversion.gen_converter(debug=True) | |
...: | |
def converter(data_, *, __v=__naive_values__["__v"]): | |
try: | |
return (data_[0] == __v) and (data_[2] > 15) | |
except __exceptions_to_dump_sources: | |
__convtools__code_storage.dump_sources() | |
raise | |
In [6]: converter | |
Out[6]: <function _convtools.converter(data_, *, __v=b'abc')> | |
"""Of course I'd suggest building the full conversion pipeline, so convtools | |
can inline as much as possible, e.g.:""" | |
In [8]: c.filter( | |
...: c.and_( | |
...: c.item(0) == b"abc", | |
...: c.item(2) > 15, | |
...: ) | |
...: ).gen_converter(debug=True) | |
...: | |
def converter(data_, *, __v=__naive_values__["__v"]): | |
try: | |
return (i_ for i_ in data_ if ((i_[0] == __v) and (i_[2] > 15))) | |
except __exceptions_to_dump_sources: | |
__convtools__code_storage.dump_sources() | |
raise | |
Out[8]: <function _convtools.converter(data_, *, __v=b'abc')> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
of course, remove
debug=True
not to print generated code, formatted withblack
.Here's the link to convtools library - https://github.com/westandskif/convtools