PK!0y threadop.pyimport ast import inspect from textwrap import dedent class _ThreadopTransformer(ast.NodeTransformer): def visit_FunctionDef(self, node): node.decorator_list = [ decorator for decorator in node.decorator_list if not isinstance(decorator, ast.Name) or decorator.id != "enable_threadop" ] self.generic_visit(node) return node def visit_BinOp(self, node): self.generic_visit(node) if isinstance(node.op, ast.BitOr): if not isinstance(node.right, ast.Call): raise RuntimeError("The RHS of a | must be a call.") node.right.args.insert(0, node.left) return node.right return node def enable_threadop(fn): """Transform all occurrences of the right shift operator by moving the left-hand expression into the right first argument position of the right-hand expression. For example, it turns:: 42 | add(2) | multiply(10) | print() into:: print(multiply(add(42, 2), 10)) Limitations: * The right-hand side *must* be a function call. * Requires access to functions' source code. """ transformer = _ThreadopTransformer() tree = transformer.visit(ast.parse(dedent(inspect.getsource(fn)))) code = compile(tree, inspect.getfile(fn), "exec") scope = {} exec(code, fn.__globals__, scope) return scope[fn.__name__] PK!HS@VXthreadop-0.1.1.dist-info/WHEEL 1 0 нRn>Z(8_@ cfM6߅Ur$o­cbaP>PK!Hr#Q!threadop-0.1.1.dist-info/METADATAN!<ż۪M8AcnQc)Ia&}{AWo`)ƌ+d+X˕Б|.䪤Ƴ^7"fs>uM2< A|*v6 D d֑C{R q1;Q쇥"/A)OЇt~Dt.CoY֭}m46}yl\5V|PK!H threadop-0.1.1.dist-info/RECORDu̱r0o :pIc"gEE*9ۡ_WۢL/0"\!볐hlByĎkO׆VvF*#0w!teOSshg钱g6g!+3_j5 / ܬNc\i+ŞnS7ba˝ױdDH PK!0y threadop.pyPK!HS@VXthreadop-0.1.1.dist-info/WHEELPK!Hr#Q!Lthreadop-0.1.1.dist-info/METADATAPK!H kthreadop-0.1.1.dist-info/RECORDPK!o