Author: Ronan Lamy <[email protected]>
Branch: py3.5
Changeset: r93120:83b96bb9cf44
Date: 2017-11-21 21:49 +0000
http://bitbucket.org/pypy/pypy/changeset/83b96bb9cf44/

Log:    Adapt idlelib.CallTips for pypy and update some docstrings

diff --git a/lib-python/3/idlelib/CallTips.py b/lib-python/3/idlelib/CallTips.py
--- a/lib-python/3/idlelib/CallTips.py
+++ b/lib-python/3/idlelib/CallTips.py
@@ -123,6 +123,15 @@
 _first_param = re.compile('(?<=\()\w*\,?\s*')
 _default_callable_argspec = "See source or doc"
 
+def _is_user_method(ob):
+    """Detect user methods on PyPy"""
+    return (isinstance(ob, types.MethodType) and
+        isinstance(ob.__code__, types.CodeType))
+
+def _is_user_function(ob):
+    """Detect user methods on PyPy"""
+    return (isinstance(ob, types.FunctionType) and
+        isinstance(ob.__code__, types.CodeType))
 
 def get_argspec(ob):
     '''Return a string describing the signature of a callable object, or ''.
@@ -140,21 +149,21 @@
         return argspec
     if isinstance(ob, type):
         fob = ob.__init__
-    elif isinstance(ob_call, types.MethodType):
+    elif _is_user_method(ob_call):
         fob = ob_call
     else:
         fob = ob
     if (isinstance(fob, (types.FunctionType, types.MethodType)) and
             hasattr(fob.__code__, 'co_code')):  # PyPy: not on <builtin-code>
         argspec = inspect.formatargspec(*inspect.getfullargspec(fob))
-        if (isinstance(ob, (type, types.MethodType)) or
-                isinstance(ob_call, types.MethodType)):
+        if (_is_user_method(ob) or _is_user_method(ob_call) or
+                (isinstance(ob, type) and _is_user_function(fob))):
             argspec = _first_param.sub("", argspec)
 
     lines = (textwrap.wrap(argspec, _MAX_COLS, subsequent_indent=_INDENT)
             if len(argspec) > _MAX_COLS else [argspec] if argspec else [])
 
-    if isinstance(ob_call, types.MethodType):
+    if _is_user_method(ob_call):
         doc = ob_call.__doc__
     else:
         doc = getattr(ob, "__doc__", "")
diff --git a/lib-python/3/idlelib/idle_test/test_calltips.py 
b/lib-python/3/idlelib/idle_test/test_calltips.py
--- a/lib-python/3/idlelib/idle_test/test_calltips.py
+++ b/lib-python/3/idlelib/idle_test/test_calltips.py
@@ -63,7 +63,7 @@
         gtest([].append, append_doc)
         gtest(List.append, append_doc)
 
-        gtest(types.MethodType, "method(function, instance)")
+        gtest(types.MethodType, "instancemethod(function, instance, class)")
         gtest(SB(), default_tip)
 
     def test_signature_wrap(self):
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -400,11 +400,13 @@
     lltype.render_immortal(ptr.c_ml_name)
     rffi.setintfield(ptr, 'c_ml_flags', METH_VARARGS | METH_KEYWORDS)
     ptr.c_ml_doc = rffi.cast(rffi.CONST_CCHARP, rffi.str2charp(
-        "T.__new__(S, ...) -> a new object with type S, a subtype of T"))
+        "Create and return a new object.  "
+        "See help(type) for accurate signature."))
     lltype.render_immortal(ptr.c_ml_doc)
     state.new_method_def = ptr
     return ptr
 
+
 def setup_new_method_def(space):
     ptr = get_new_method_def(space)
     ptr.c_ml_meth = rffi.cast(PyCFunction, llslot(space, tp_new_wrapper))
diff --git a/pypy/objspace/std/boolobject.py b/pypy/objspace/std/boolobject.py
--- a/pypy/objspace/std/boolobject.py
+++ b/pypy/objspace/std/boolobject.py
@@ -40,7 +40,7 @@
     @staticmethod
     @unwrap_spec(w_obj=WrappedDefault(False))
     def descr_new(space, w_booltype, w_obj):
-        """T.__new__(S, ...) -> a new object with type S, a subtype of T"""
+        "Create and return a new object.  See help(type) for accurate 
signature."
         space.w_bool.check_user_subclass(w_booltype)
         return space.newbool(space.is_true(w_obj))
 
diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -658,7 +658,7 @@
         """x.__imul__(y) <==> x*=y"""
 
     def __init__():
-        """x.__init__(...) initializes x; see help(type(x)) for signature"""
+        """Initialize self.  See help(type(self)) for accurate signature."""
 
     def __iter__():
         """x.__iter__() <==> iter(x)"""
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -514,7 +514,7 @@
     @staticmethod
     @unwrap_spec(w_x=WrappedDefault(0))
     def descr_new(space, w_inttype, w_x, w_base=None):
-        """T.__new__(S, ...) -> a new object with type S, a subtype of T"""
+        "Create and return a new object.  See help(type) for accurate 
signature."
         return _new_int(space, w_inttype, w_x, w_base)
 
     def descr_hash(self, space):
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -301,7 +301,7 @@
         return self.strategy.find(self, w_item, start, end)
 
     def append(self, w_item):
-        """L.append(object) -- append object to end"""
+        """L.append(object) -> None -- append object to end"""
         self.strategy.append(self, w_item)
 
     def length(self):
@@ -403,8 +403,7 @@
         self.strategy.insert(self, index, w_item)
 
     def extend(self, w_iterable):
-        '''L.extend(iterable) -- extend list by appending
-        elements from the iterable'''
+        '''L.extend(iterable) -- extend list by appending elements from the 
iterable'''
         self.strategy.extend(self, w_iterable)
 
     def reverse(self):
@@ -420,13 +419,13 @@
 
     @staticmethod
     def descr_new(space, w_listtype, __args__):
-        """T.__new__(S, ...) -> a new object with type S, a subtype of T"""
+        "Create and return a new object.  See help(type) for accurate 
signature."
         w_obj = space.allocate_instance(W_ListObject, w_listtype)
         w_obj.clear(space)
         return w_obj
 
     def descr_init(self, space, __args__):
-        """x.__init__(...) initializes x; see help(type(x)) for signature"""
+        """Initialize self.  See help(type(self)) for accurate signature."""
         # this is on the silly side
         w_iterable, = __args__.parse_obj(
                 None, 'list', init_signature, init_defaults)
@@ -603,8 +602,7 @@
         self.reverse()
 
     def descr_count(self, space, w_value):
-        '''L.count(value) -> integer -- return number of
-        occurrences of value'''
+        '''L.count(value) -> integer -- return number of occurrences of 
value'''
         # needs to be safe against eq_w() mutating the w_list behind our back
         count = 0
         i = 0
@@ -623,8 +621,8 @@
 
     @unwrap_spec(index=int)
     def descr_pop(self, space, index=-1):
-        '''L.pop([index]) -> item -- remove and return item at
-        index (default last)'''
+        """L.pop([index]) -> item -- remove and return item at index (default 
last).
+Raises IndexError if list is empty or index is out of range."""
         length = self.length()
         if length == 0:
             raise oefmt(space.w_IndexError, "pop from empty list")
@@ -639,7 +637,7 @@
             raise oefmt(space.w_IndexError, "pop index out of range")
 
     def descr_clear(self, space):
-        '''L.clear() -- remove all items'''
+        """L.clear() -> None -- remove all items from L"""
         self.clear(space)
 
     def descr_copy(self, space):
@@ -647,7 +645,8 @@
         return self.clone()
 
     def descr_remove(self, space, w_value):
-        'L.remove(value) -- remove first occurrence of value'
+        """L.remove(value) -> None -- remove first occurrence of value.
+Raises ValueError if the value is not present."""
         # needs to be safe against eq_w() mutating the w_list behind our back
         try:
             i = self.find(w_value, 0, sys.maxint)
@@ -659,8 +658,8 @@
 
     @unwrap_spec(w_start=WrappedDefault(0), w_stop=WrappedDefault(sys.maxint))
     def descr_index(self, space, w_value, w_start, w_stop):
-        '''L.index(value, [start, [stop]]) -> integer -- return
-        first index of value'''
+        """L.index(value, [start, [stop]]) -> integer -- return first index of 
value.
+Raises ValueError if the value is not present."""
         # needs to be safe against eq_w() mutating the w_list behind our back
         size = self.length()
         i, stop = unwrap_start_stop(space, size, w_start, w_stop)
@@ -673,8 +672,7 @@
 
     @unwrap_spec(reverse=int)
     def descr_sort(self, space, w_key=None, reverse=False):
-        """ L.sort(key=None, reverse=False) -- stable
-        sort *IN PLACE*"""
+        """L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*"""
         has_key = not space.is_none(w_key)
 
         # create and setup a TimSort instance
diff --git a/pypy/objspace/std/noneobject.py b/pypy/objspace/std/noneobject.py
--- a/pypy/objspace/std/noneobject.py
+++ b/pypy/objspace/std/noneobject.py
@@ -9,7 +9,7 @@
 
     @staticmethod
     def descr_new(space, w_type):
-        """T.__new__(S, ...) -> a new object with type S, a subtype of T"""
+        "Create and return a new object.  See help(type) for accurate 
signature."
         return space.w_None
 
     def descr_bool(self, space):
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -445,8 +445,8 @@
 
     def test_doc(self):
         assert list.__doc__ == "list() -> new empty list\nlist(iterable) -> 
new list initialized from iterable's items"
-        assert list.__new__.__doc__ == "T.__new__(S, ...) -> a new object with 
type S, a subtype of T"
-        assert list.__init__.__doc__ == "x.__init__(...) initializes x; see 
help(type(x)) for signature"
+        assert list.__new__.__doc__ == "Create and return a new object.  See 
help(type) for accurate signature."
+        assert list.__init__.__doc__ == "Initialize self.  See 
help(type(self)) for accurate signature."
 
     def test_getstrategyfromlist_w(self):
         l0 = ["a", "2", "a", True]
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to