Skip to content

Instantly share code, notes, and snippets.

@yu-iskw
Created September 9, 2015 08:37
Show Gist options
  • Save yu-iskw/9f5a702b6657c1887b9b to your computer and use it in GitHub Desktop.
Save yu-iskw/9f5a702b6657c1887b9b to your computer and use it in GitHub Desktop.
Check @SInCE
def since(version):
"""
A decorator that annotates a function to append the version of Spark the function was added.
"""
import re
indent_p = re.compile(r'\n( +)')
def deco(f):
if f.__doc__ is None:
f.__doc__ = ".. versionadded:: %s" % (version)
f.__doc__ = str(type(f))
else:
indents = indent_p.findall(f.__doc__)
indent = ' ' * (min(len(m) for m in indents) if indents else 0)
f.__doc__ = str(type(f))
f.__doc__ = f.__doc__.rstrip() + "\n\n%s.. versionadded:: %s" % (indent, version)
return f
return deco
@since("1.6.0")
class Foo(object):
@since("1.6.0")
@staticmethod
def sm():
return 1
@classmethod
@since("1.6.0")
def cm(cls):
return 1
@since("1.6.0")
def im(self):
return 1
@property
@since("1.6.0")
def pm(self):
return 1
print(type(Foo.sm))
print(type(Foo.cm))
print(type(Foo.im))
print(type(Foo.pm))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment