[issue26632] __all__ decorator
Ethan Furman
report at bugs.python.org
Wed Mar 23 22:48:08 EDT 2016
Ethan Furman added the comment:
def public(thing, value=None):
if isinstance(thing, str):
mdict = sys._getframe(1).f_globals
name = thing
mdict[name] = thing # no need for retyping! ;)
else:
mdict = sys.modules[thing.__module__].__dict__
name = thing.__name__
dunder_all = mdict.setdefault('__all__', [])
dunder_all.append(name)
return thing
@public
def baz(a, b):
return a+ b
public('CONST1', 3)
CONST2 = 4
----------------------------
On the down side, you know somebody is going to @public a class' method -- how do we check for that?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26632>
_______________________________________
More information about the Python-bugs-list
mailing list