A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20040418/6aaee156/docslots.py below:

"""Sample implementation of the docslots idea.""" import sys class slotproperty(object): def __init__(self, name, docstring): self.__name__ = name self.__doc__ = docstring self._slotname = "_slotproperty_" + name def __get__(self, inst, cls=None): return getattr(inst, self._slotname) def __set__(self, inst, value): setattr(inst, self._slotname, value) def docslots(**kw): namespace = sys._getframe(1).f_locals __slots__ = namespace.get("__slots__", ()) __slots__ = list(__slots__) for name, docstring in kw.iteritems(): prop = slotproperty(name, docstring) if name in __slots__: __slots__.remove(name) __slots__.append(prop._slotname) namespace[name] = prop namespace["__slots__"] = tuple(__slots__) class SampleClass(object): docslots(slot1="description", slot2=("Some long\n" "multi-line description.")) d = SampleClass.__dict__ assert d["slot1"].__doc__ == "description" assert d["slot2"].__doc__ == "Some long\nmulti-line description." inst = SampleClass() inst.slot1 = 42 assert inst.slot1 == 42

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4