John Vandenberg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/169788
Change subject: Detect epydoc and disable decorators, etc
......................................................................
Detect epydoc and disable decorators, etc
epydoc breaks when it encounters 'pywikibot' is of type
ModuleDeprecationWrapper. It also warns of missing parameters
when a function/method uses a decorator, as the decorator hides the
original function/method.
Bug: 72424
Change-Id: I67ed6b3e79ac46ef92e2b08ef6c606fd7177bae2
---
M pywikibot/site.py
M pywikibot/tools.py
2 files changed, 52 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/88/169788/1
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 9cadefe..7b57b09 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -29,7 +29,7 @@
import pywikibot.family
from pywikibot.tools import (
itergroup, deprecated, deprecate_arg, UnicodeMixin, ComparableMixin,
- redirect_func, add_decorated_full_name, deprecated_args
+ redirect_func, add_decorated_full_name, deprecated_args, is_epydoc,
)
from pywikibot.tools import MediaWikiVersion as LV
from pywikibot.throttle import Throttle
@@ -930,6 +930,10 @@
else:
raise Exception("Not implemented")
return fn(self, *args, **kwargs)
+
+ if is_epydoc():
+ return fn
+
callee.__name__ = fn.__name__
callee.__doc__ = fn.__doc__
callee.__module__ = callee.__module__
@@ -956,6 +960,10 @@
u"isn't implemented in MediaWiki version < %s"
% (fn.__name__, version))
return fn(self, *args, **kwargs)
+
+ if is_epydoc():
+ return fn
+
callee.__name__ = fn.__name__
callee.__doc__ = fn.__doc__
callee.__module__ = fn.__module__
diff --git a/pywikibot/tools.py b/pywikibot/tools.py
index 39f31ca..ac81967 100644
--- a/pywikibot/tools.py
+++ b/pywikibot/tools.py
@@ -357,6 +357,34 @@
# only one arg, and that arg be a callable, as it will be detected as
# a deprecator without any arguments.
+_is_epydoc = None
+
+
+def is_epydoc():
+ """
+ Detect epydoc.
+
+ @return: True if loaded by epydoc
+ @rtype: bool
+ """
+ global _is_epydoc
+
+ if _is_epydoc is not None:
+ return _is_epydoc
+
+ caller = inspect.currentframe().f_back.f_back
+ while caller:
+ caller_module = inspect.getmodule(caller)
+ if caller_module.__name__.startswith('epydoc'):
+ warning('epydoc detected')
+ _is_epydoc = True
+ return True
+
+ caller = caller.f_back
+
+ _is_epydoc = False
+ return False
+
def add_decorated_full_name(obj):
"""Extract full object name, including class, and store in __full_name__.
@@ -438,6 +466,9 @@
else:
return inner_wrapper
+ if is_epydoc():
+ return obj
+
return outer_wrapper
@@ -473,6 +504,9 @@
warning(u"%s is deprecated." % (name))
return obj(*args, **kwargs)
+ if is_epydoc():
+ return obj
+
wrapper.__doc__ = obj.__doc__
wrapper.__name__ = obj.__name__
wrapper.__module__ = obj.__module__
@@ -488,6 +522,9 @@
# When called as @deprecated, return a replacement function
if without_parameters:
+ if is_epydoc():
+ return args[0]
+
return decorator(args[0])
# Otherwise return a decorator, which returns a replacement function
else:
@@ -547,6 +584,9 @@
"deprecated." % locals(), _logger)
del __kw[old_arg]
return obj(*__args, **__kw)
+
+ if is_epydoc():
+ return obj
wrapper.__doc__ = obj.__doc__
wrapper.__name__ = obj.__name__
@@ -627,7 +667,9 @@
module = sys.modules[module]
super(ModuleDeprecationWrapper, self).__setattr__('_deprecated', {})
super(ModuleDeprecationWrapper, self).__setattr__('_module', module)
- sys.modules[module.__name__] = self
+
+ if not is_epydoc():
+ sys.modules[module.__name__] = self
def _add_deprecated_attr(self, name, replacement=None,
replacement_name=None):
--
To view, visit https://gerrit.wikimedia.org/r/169788
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I67ed6b3e79ac46ef92e2b08ef6c606fd7177bae2
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits