Skip to content

Commit

Permalink
test for qualname in get_typedef_type (#613)
Browse files Browse the repository at this point in the history
* test for qualname in get_typedef_type

* adjust float test for pypy, test tuple and None
  • Loading branch information
mmckerns committed Aug 19, 2023
1 parent 64aaefb commit 2fbe2e1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ def _get_typedict_type(cls, clsdict, attrs, postproc_list):
for name, value in dict.items(clsdict):
try:
base_value = inherited_dict[name]
if value is base_value:
if value is base_value and hasattr(value, '__qualname__'):
to_remove.append(name)
except KeyError:
pass
Expand Down
5 changes: 3 additions & 2 deletions dill/tests/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def test_abc_non_local():
# Set a property that StockPickle can't preserve
instance.bar = lambda x: x**2
depickled = dill.copy(instance)
assert type(depickled) is not type(instance)
assert type(depickled) is type(instance) #NOTE: issue #612, test_abc_local
#NOTE: dill.copy of local (or non-local) classes should (not) be the same?
assert type(depickled.bar) is FunctionType
assert depickled.bar(3) == 9
assert depickled.sfoo() == "Static Method SFOO"
Expand All @@ -99,7 +100,7 @@ def baz(self):
labc = dill.copy(LocalABC)
assert labc is not LocalABC
assert type(labc) is type(LocalABC)
# TODO should work like it does for non local classes
#NOTE: dill.copy of local (or non-local) classes should (not) be the same?
# <class '__main__.LocalABC'>
# <class '__main__.test_abc_local.<locals>.LocalABC'>

Expand Down
49 changes: 49 additions & 0 deletions dill/tests/test_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,54 @@ def test_enummeta():
assert dill.copy(HTTPStatus.OK) is HTTPStatus.OK
assert dill.copy(enum.EnumMeta) is enum.EnumMeta

def test_inherit(): #NOTE: see issue #612
class Foo:
w = 0
x = 1
y = 1.1
a = ()
b = (1,)
n = None

class Bar(Foo):
w = 2
x = 1
y = 1.1
z = 0.2
a = ()
b = (1,)
c = (2,)
n = None

Baz = dill.copy(Bar)

import platform
is_pypy = platform.python_implementation() == 'PyPy'
assert Bar.__dict__ == Baz.__dict__
# ints
assert 'w' in Bar.__dict__ and 'w' in Baz.__dict__
assert Bar.__dict__['w'] is Baz.__dict__['w']
assert 'x' in Bar.__dict__ and 'x' in Baz.__dict__
assert Bar.__dict__['x'] is Baz.__dict__['x']
# floats
assert 'y' in Bar.__dict__ and 'y' in Baz.__dict__
same = Bar.__dict__['y'] is Baz.__dict__['y']
assert same if is_pypy else not same
assert 'z' in Bar.__dict__ and 'z' in Baz.__dict__
same = Bar.__dict__['z'] is Baz.__dict__['z']
assert same if is_pypy else not same
# tuples
assert 'a' in Bar.__dict__ and 'a' in Baz.__dict__
assert Bar.__dict__['a'] is Baz.__dict__['a']
assert 'b' in Bar.__dict__ and 'b' in Baz.__dict__
assert Bar.__dict__['b'] is not Baz.__dict__['b']
assert 'c' in Bar.__dict__ and 'c' in Baz.__dict__
assert Bar.__dict__['c'] is not Baz.__dict__['c']
# None
assert 'n' in Bar.__dict__ and 'n' in Baz.__dict__
assert Bar.__dict__['n'] is Baz.__dict__['n']


if __name__ == '__main__':
test_class_instances()
test_class_objects()
Expand All @@ -289,3 +337,4 @@ def test_enummeta():
test_origbases()
test_metaclass()
test_enummeta()
test_inherit()

0 comments on commit 2fbe2e1

Please sign in to comment.