commons._utils.export()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 24
rs 9.75
c 0
b 0
f 0
cc 4
nop 1
1
import sys
2
3
from typing import Any
4
5
6
def export(target: Any) -> Any:
7
  """
8
  Mark a module-level object as exported.
9
10
  Simplifies tracking of objects available via wildcard imports.
11
12
  """
13
  mod = sys.modules[target.__module__]
14
15
  __all__ = getattr(mod, '__all__', None)
16
17
  if __all__ is None:
18
    __all__ = []
19
    setattr(mod, '__all__', __all__)
20
21
  elif not isinstance(__all__, list):
22
    __all__ = list(__all__)
23
    setattr(mod, '__all__', __all__)
24
25
  target_name = target.__name__
26
  if target_name not in __all__:
27
    __all__.append(target_name)
28
29
  return target
30