summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-05-26 19:12:38 (GMT)
committerGuido van Rossum <guido@python.org>2006-05-26 19:12:38 (GMT)
commit65810fee5e961af07fb964252b794c67162f98ee (patch)
tree7400532588af74faa31a12c31492839ab2e06c9a /Lib
parent2018831b2b2106499a43b37e49e24f7f14154d35 (diff)
downloadcpython-65810fee5e961af07fb964252b794c67162f98ee.zip
cpython-65810fee5e961af07fb964252b794c67162f98ee.tar.gz
cpython-65810fee5e961af07fb964252b794c67162f98ee.tar.bz2
SF patch 1495675: Remove types.InstanceType and new.instance
(Collin Winter)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/copy.py43
-rw-r--r--Lib/dis.py2
-rw-r--r--Lib/new.py1
-rw-r--r--Lib/pickle.py40
-rw-r--r--Lib/pickletools.py76
-rw-r--r--Lib/test/output/test_new1
-rw-r--r--Lib/test/test_new.py14
-rw-r--r--Lib/types.py6
-rw-r--r--Lib/xmlrpclib.py1
9 files changed, 50 insertions, 134 deletions
diff --git a/Lib/copy.py b/Lib/copy.py
index 35c666f..f9e403d 100644
--- a/Lib/copy.py
+++ b/Lib/copy.py
@@ -119,26 +119,6 @@ def _copy_with_copy_method(x):
if PyStringMap is not None:
d[PyStringMap] = _copy_with_copy_method
-def _copy_inst(x):
- if hasattr(x, '__copy__'):
- return x.__copy__()
- if hasattr(x, '__getinitargs__'):
- args = x.__getinitargs__()
- y = x.__class__(*args)
- else:
- y = _EmptyClass()
- y.__class__ = x.__class__
- if hasattr(x, '__getstate__'):
- state = x.__getstate__()
- else:
- state = x.__dict__
- if hasattr(y, '__setstate__'):
- y.__setstate__(state)
- else:
- y.__dict__.update(state)
- return y
-d[types.InstanceType] = _copy_inst
-
del d
def deepcopy(x, memo=None, _nil=[]):
@@ -273,29 +253,6 @@ def _keep_alive(x, memo):
# aha, this is the first one :-)
memo[id(memo)]=[x]
-def _deepcopy_inst(x, memo):
- if hasattr(x, '__deepcopy__'):
- return x.__deepcopy__(memo)
- if hasattr(x, '__getinitargs__'):
- args = x.__getinitargs__()
- args = deepcopy(args, memo)
- y = x.__class__(*args)
- else:
- y = _EmptyClass()
- y.__class__ = x.__class__
- memo[id(x)] = y
- if hasattr(x, '__getstate__'):
- state = x.__getstate__()
- else:
- state = x.__dict__
- state = deepcopy(state, memo)
- if hasattr(y, '__setstate__'):
- y.__setstate__(state)
- else:
- y.__dict__.update(state)
- return y
-d[types.InstanceType] = _deepcopy_inst
-
def _reconstruct(x, info, deep, memo=None):
if isinstance(info, str):
return x
diff --git a/Lib/dis.py b/Lib/dis.py
index 5a74b3a..89caf20 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -18,8 +18,6 @@ def dis(x=None):
if x is None:
distb()
return
- if type(x) is types.InstanceType:
- x = x.__class__
if hasattr(x, 'im_func'):
x = x.im_func
if hasattr(x, 'func_code'):
diff --git a/Lib/new.py b/Lib/new.py
index 99a1c3f..bee11ed 100644
--- a/Lib/new.py
+++ b/Lib/new.py
@@ -6,7 +6,6 @@ Objects of most types can now be created by calling the type object.
from types import ClassType as classobj
from types import FunctionType as function
-from types import InstanceType as instance
from types import MethodType as instancemethod
from types import ModuleType as module
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 02a1b1d..ccda3e7 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -687,46 +687,6 @@ class Pickler:
write(SETITEM)
# else tmp is empty, and we're done
- def save_inst(self, obj):
- cls = obj.__class__
-
- memo = self.memo
- write = self.write
- save = self.save
-
- if hasattr(obj, '__getinitargs__'):
- args = obj.__getinitargs__()
- len(args) # XXX Assert it's a sequence
- _keep_alive(args, memo)
- else:
- args = ()
-
- write(MARK)
-
- if self.bin:
- save(cls)
- for arg in args:
- save(arg)
- write(OBJ)
- else:
- for arg in args:
- save(arg)
- write(INST + cls.__module__ + '\n' + cls.__name__ + '\n')
-
- self.memoize(obj)
-
- try:
- getstate = obj.__getstate__
- except AttributeError:
- stuff = obj.__dict__
- else:
- stuff = getstate()
- _keep_alive(stuff, memo)
- save(stuff)
- write(BUILD)
-
- dispatch[InstanceType] = save_inst
-
def save_global(self, obj, name=None, pack=struct.pack):
write = self.write
memo = self.memo
diff --git a/Lib/pickletools.py b/Lib/pickletools.py
index 98f80f1..ab5e247 100644
--- a/Lib/pickletools.py
+++ b/Lib/pickletools.py
@@ -2071,42 +2071,58 @@ highest protocol among opcodes = 0
0: ( MARK
1: l LIST (MARK at 0)
2: p PUT 0
- 5: ( MARK
- 6: i INST 'pickletools _Example' (MARK at 5)
- 28: p PUT 1
- 31: ( MARK
- 32: d DICT (MARK at 31)
- 33: p PUT 2
- 36: S STRING 'value'
- 45: p PUT 3
- 48: I INT 42
- 52: s SETITEM
- 53: b BUILD
- 54: a APPEND
- 55: g GET 1
- 58: a APPEND
- 59: . STOP
+ 5: c GLOBAL 'copy_reg _reconstructor'
+ 30: p PUT 1
+ 33: ( MARK
+ 34: c GLOBAL 'pickletools _Example'
+ 56: p PUT 2
+ 59: c GLOBAL '__builtin__ object'
+ 79: p PUT 3
+ 82: N NONE
+ 83: t TUPLE (MARK at 33)
+ 84: p PUT 4
+ 87: R REDUCE
+ 88: p PUT 5
+ 91: ( MARK
+ 92: d DICT (MARK at 91)
+ 93: p PUT 6
+ 96: S STRING 'value'
+ 105: p PUT 7
+ 108: I INT 42
+ 112: s SETITEM
+ 113: b BUILD
+ 114: a APPEND
+ 115: g GET 5
+ 118: a APPEND
+ 119: . STOP
highest protocol among opcodes = 0
>>> dis(pickle.dumps(x, 1))
0: ] EMPTY_LIST
1: q BINPUT 0
3: ( MARK
- 4: ( MARK
- 5: c GLOBAL 'pickletools _Example'
- 27: q BINPUT 1
- 29: o OBJ (MARK at 4)
- 30: q BINPUT 2
- 32: } EMPTY_DICT
- 33: q BINPUT 3
- 35: U SHORT_BINSTRING 'value'
- 42: q BINPUT 4
- 44: K BININT1 42
- 46: s SETITEM
- 47: b BUILD
- 48: h BINGET 2
- 50: e APPENDS (MARK at 3)
- 51: . STOP
+ 4: c GLOBAL 'copy_reg _reconstructor'
+ 29: q BINPUT 1
+ 31: ( MARK
+ 32: c GLOBAL 'pickletools _Example'
+ 54: q BINPUT 2
+ 56: c GLOBAL '__builtin__ object'
+ 76: q BINPUT 3
+ 78: N NONE
+ 79: t TUPLE (MARK at 31)
+ 80: q BINPUT 4
+ 82: R REDUCE
+ 83: q BINPUT 5
+ 85: } EMPTY_DICT
+ 86: q BINPUT 6
+ 88: U SHORT_BINSTRING 'value'
+ 95: q BINPUT 7
+ 97: K BININT1 42
+ 99: s SETITEM
+ 100: b BUILD
+ 101: h BINGET 5
+ 103: e APPENDS (MARK at 3)
+ 104: . STOP
highest protocol among opcodes = 1
Try "the canonical" recursive-object test.
diff --git a/Lib/test/output/test_new b/Lib/test/output/test_new
index b7f2ed9..fd225f3 100644
--- a/Lib/test/output/test_new
+++ b/Lib/test/output/test_new
@@ -1,7 +1,6 @@
test_new
new.module()
new.classobj()
-new.instance()
new.instancemethod()
new.function()
new.code()
diff --git a/Lib/test/test_new.py b/Lib/test/test_new.py
index 4aab1e2..2819923 100644
--- a/Lib/test/test_new.py
+++ b/Lib/test/test_new.py
@@ -21,22 +21,12 @@ print 'new.classobj()'
C = new.classobj('Spam', (Spam.Eggs,), {'get_more_yolks': get_more_yolks})
if verbose:
print C
-print 'new.instance()'
-c = new.instance(C, {'yolks': 3})
-if verbose:
- print c
-o = new.instance(C)
-verify(o.__dict__ == {},
- "new __dict__ should be empty")
-del o
-o = new.instance(C, None)
-verify(o.__dict__ == {},
- "new __dict__ should be empty")
-del o
def break_yolks(self):
self.yolks = self.yolks - 2
print 'new.instancemethod()'
+c = C()
+c.yolks = 3
im = new.instancemethod(break_yolks, c, C)
if verbose:
print im
diff --git a/Lib/types.py b/Lib/types.py
index 39812ac..db63c96 100644
--- a/Lib/types.py
+++ b/Lib/types.py
@@ -56,9 +56,7 @@ class _C:
def _m(self): pass
ClassType = type(_C)
UnboundMethodType = type(_C._m) # Same as MethodType
-_x = _C()
-InstanceType = type(_x)
-MethodType = type(_x._m)
+MethodType = type(_C()._m)
BuiltinFunctionType = type(len)
BuiltinMethodType = type([].append) # Same as BuiltinFunctionType
@@ -86,4 +84,4 @@ EllipsisType = type(Ellipsis)
DictProxyType = type(TypeType.__dict__)
NotImplementedType = type(NotImplemented)
-del sys, _f, _g, _C, _x # Not for export
+del sys, _f, _g, _C # Not for export
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index bac0a9f..2938f29 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -748,7 +748,6 @@ class Marshaller:
else:
# store instance attributes as a struct (really?)
self.dump_struct(value.__dict__, write)
- dispatch[InstanceType] = dump_instance
dispatch[DateTime] = dump_instance
dispatch[Binary] = dump_instance