Debian Codegraph @

tests/cloudpickle_testpkg/_cloudpickle_testpkg/__init__.py

raw
1 import typing
2 from . import mod # noqa
3
4
5 def package_function():
6 """Function living inside a package, not a simple module"""
7 return "hello from a package!"
8
9
10 global_variable = "some global variable"
11
12
13 def package_function_with_global():
14 global global_variable
15 return global_variable
16
17
18 class _SingletonClass:
19 def __reduce__(self):
20 # This reducer is only valid for the top level "some_singleton" object.
21 return "some_singleton"
22
23
24 def relative_imports_factory():
25 """Factory creating dynamically-defined functions using relative imports
26
27 Relative import of functions living both inside modules and packages are
28 tested.
29 """
30
31 def f():
32 # module_function belongs to _cloudpickle_testpkg.mod, which is a
33 # module
34 from .mod import module_function
35
36 return module_function()
37
38 def g():
39 # package_function belongs to _cloudpickle_testpkg, which is a package
40 from . import package_function
41
42 return package_function()
43
44 return f, g
45
46
47 some_singleton = _SingletonClass()
48 T = typing.TypeVar("T")