Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'dill' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
def run_source(obj):
_obj = source._wrap(obj)
assert _obj(1.57) == obj(1.57)
src = source.getimportable(obj, alias='_f')
exec(src, globals())
assert _f(1.57) == obj(1.57)
name = source.getname(obj)
assert name == obj.__name__ or src.split("=",1)[0].strip()
def run_source(obj):
_obj = source._wrap(obj)
assert _obj(1.57) == obj(1.57)
src = source.importable(obj, alias='_f')
# LEEK: for 3.x, locals may not be modified
# (see https://docs.python.org/3.6/library/functions.html#locals)
#
my_locals = locals()
exec(src, globals(), my_locals)
assert my_locals["_f"](1.57) == obj(1.57)
name = source.getname(obj)
assert name == obj.__name__ or src.split("=",1)[0].strip()
def run_source(obj):
_obj = source._wrap(obj)
assert _obj(1.57) == obj(1.57)
src = source.getimportable(obj, alias='_f')
exec(src, globals())
assert _f(1.57) == obj(1.57)
name = source.getname(obj)
assert name == obj.__name__ or src.split("=",1)[0].strip()
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2008-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
import sys
import dill
import test_mixins as module
try: from imp import reload
except ImportError: pass
dill.settings['recurse'] = True
cached = (module.__cached__ if hasattr(module, "__cached__")
else module.__file__.split(".", 1)[0] + ".pyc")
module.a = 1234
pik_mod = dill.dumps(module)
module.a = 0
# remove module
del sys.modules[module.__name__]
del module
module = dill.loads(pik_mod)
def test_attributes():
double_add.invert()
assert double_add(1,2,3) == -2*fx
_d = dill.copy(double_add)
assert _d(1,2,3) == -2*fx
#_d.invert() #FIXME: fails seemingly randomly
#assert _d(1,2,3) == 2*fx
assert _d.__wrapped__(1,2,3) == fx
# XXX: issue or feature? in python3.4, inverted is linked through copy
if not double_add.inverted[0]:
double_add.invert()
# test some stuff from source and pointers
ds = dill.source
dd = dill.detect
assert ds.getsource(dd.freevars(quadish)['f']) == '@quad_factory(a=0,b=4,c=0)\ndef quadish(x):\n return x+1\n'
assert ds.getsource(dd.freevars(quadruple)['f']) == '@doubler\ndef quadruple(x):\n return 2*x\n'
assert ds.importable(quadish, source=False) == 'from %s import quadish\n' % __name__
assert ds.importable(quadruple, source=False) == 'from %s import quadruple\n' % __name__
assert ds.importable(quadratic, source=False) == 'from %s import quadratic\n' % __name__
assert ds.importable(double_add, source=False) == 'from %s import double_add\n' % __name__
assert ds.importable(quadruple, source=True) == 'def doubler(f):\n def inner(*args, **kwds):\n fx = f(*args, **kwds)\n return 2*fx\n return inner\n\n@doubler\ndef quadruple(x):\n return 2*x\n'
#***** #FIXME: this needs work
result = ds.importable(quadish, source=True)
a,b,c,_,result = result.split('\n',4)
assert result == 'def quad_factory(a=1,b=1,c=0):\n def dec(f):\n def func(*args,**kwds):\n fx = f(*args,**kwds)\n return a*fx**2 + b*fx + c\n return func\n return dec\n\n@quad_factory(a=0,b=4,c=0)\ndef quadish(x):\n return x+1\n'
assert set([a,b,c]) == set(['a = 0', 'c = 0', 'b = 4'])
result = ds.importable(quadratic, source=True)
a,b,c,result = result.split('\n',3)
assert result == '\ndef dec(f):\n def func(*args,**kwds):\n fx = f(*args,**kwds)\n return a*fx**2 + b*fx + c\n return func\n'
def run_source(obj):
_obj = source._wrap(obj)
assert _obj(1.57) == obj(1.57)
src = source.importable(obj, alias='_f')
# LEEK: for 3.x, locals may not be modified
# (see https://docs.python.org/3.6/library/functions.html#locals)
#
my_locals = locals()
exec(src, globals(), my_locals)
assert my_locals["_f"](1.57) == obj(1.57)
name = source.getname(obj)
assert name == obj.__name__ or src.split("=",1)[0].strip()
def run_source(obj):
_obj = source._wrap(obj)
assert _obj(1.57) == obj(1.57)
src = source.getimportable(obj, alias='_f')
exec(src, globals())
assert _f(1.57) == obj(1.57)
name = source.getname(obj)
assert name == obj.__name__ or src.split("=",1)[0].strip()
def run_source(obj):
_obj = source._wrap(obj)
assert _obj(1.57) == obj(1.57)
src = source.importable(obj, alias='_f')
# LEEK: for 3.x, locals may not be modified
# (see https://docs.python.org/3.6/library/functions.html#locals)
#
my_locals = locals()
exec(src, globals(), my_locals)
assert my_locals["_f"](1.57) == obj(1.57)
name = source.getname(obj)
assert name == obj.__name__ or src.split("=",1)[0].strip()
def pytest_configure_node(node):
"""
Configure node of tests.
:param node: _pytest.nodes.Node
:return: pickle of RPService
"""
if node.config._reportportal_configured is False:
# Stop now if the plugin is not properly configured
return
node.slaveinput['py_test_service'] = pickle.dumps(node.config.
py_test_service)
def test_labeling_function_serialize(self) -> None:
lf = NLPLabelingFunction(name="my_lf", f=has_person_mention, pre=[combine_text])
lf_load = dill.loads(dill.dumps(lf))
self._run_lf(lf_load)