[pypy-commit] pypy py3.5: Implement __text_signature__ on types
rlamy
pypy.commits at gmail.com
Thu Nov 9 13:12:56 EST 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r92984:ffe57298623b
Date: 2017-11-09 18:12 +0000
http://bitbucket.org/pypy/pypy/changeset/ffe57298623b/
Log: Implement __text_signature__ on types
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -16,7 +16,7 @@
@not_rpython
def __init__(self, __name, __base=None, __total_ordering__=None,
__buffer=None, __confirm_applevel_del__=False,
- variable_sized=False, **rawdict):
+ _text_signature_=None, variable_sized=False, **rawdict):
"initialization-time only"
self.name = __name
if __base is None:
@@ -36,6 +36,7 @@
assert '__del__' not in rawdict
self.weakrefable = '__weakref__' in rawdict
self.doc = rawdict.get('__doc__', None)
+ self.text_signature = _text_signature_
for base in bases:
self.hasdict |= base.hasdict
self.weakrefable |= base.weakrefable
diff --git a/pypy/objspace/std/objectobject.py b/pypy/objspace/std/objectobject.py
--- a/pypy/objspace/std/objectobject.py
+++ b/pypy/objspace/std/objectobject.py
@@ -280,6 +280,7 @@
return space.call_function(space.w_list, _objectdir(space, w_obj))
W_ObjectObject.typedef = TypeDef("object",
+ _text_signature_='()',
__doc__ = "The most base type",
__new__ = interp2app(descr__new__),
__subclasshook__ = interp2app(descr___subclasshook__, as_classmethod=True),
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -543,6 +543,13 @@
type(X).__dict__["__doc__"].__delete__(X))
assert X.__doc__ == "banana"
+ def test_text_signature(self):
+ assert object.__text_signature__ == '()'
+
+ class A:
+ pass
+ assert A.__text_signature__ is None
+
def test_metaclass_conflict(self):
"""
class T1(type):
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -185,6 +185,7 @@
self.hasuserdel = False
self.weakrefable = False
self.w_doc = space.w_None
+ self.text_signature = None
self.weak_subclasses = []
self.flag_heaptype = is_heaptype
self.flag_abstract = False
@@ -975,6 +976,11 @@
raise oefmt(space.w_TypeError, "can't set %N.__doc__", w_type)
w_type.setdictvalue(space, '__doc__', w_value)
+def type_get_txtsig(space, w_type):
+ if w_type.text_signature is None:
+ return space.w_None
+ return space.newtext(w_type.text_signature)
+
def descr__dir(space, w_type):
from pypy.objspace.std.util import _classdir
return space.call_function(space.w_list, _classdir(space, w_type))
@@ -1062,6 +1068,7 @@
__mro__ = GetSetProperty(descr_get__mro__),
__dict__=GetSetProperty(type_get_dict),
__doc__ = GetSetProperty(descr__doc, descr_set__doc, cls=W_TypeObject, name='__doc__'),
+ __text_signature__=GetSetProperty(type_get_txtsig),
__dir__ = gateway.interp2app(descr__dir),
mro = gateway.interp2app(descr_mro),
__flags__ = GetSetProperty(descr__flags),
@@ -1271,6 +1278,7 @@
else:
w_doc = w_self.space.newtext_or_none(instancetypedef.doc)
w_self.w_doc = w_doc
+ w_self.text_signature = instancetypedef.text_signature
ensure_common_attributes(w_self)
#
# usually 'instancetypedef' is new, i.e. not seen in any base,
More information about the pypy-commit
mailing list