Skip to content

Commit

Permalink
formal support for 3.12, initial support for 3.13 (#630)
Browse files Browse the repository at this point in the history
* formal support for 3.12, initial support for 3.13

* use NamedTemporaryFile('w').file in 3.13
  • Loading branch information
mmckerns authored Nov 4, 2023
1 parent f66ed3b commit 4b24b6d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ matrix:
- python: '3.11'
env:

- python: '3.12-dev'
- python: '3.12'
env:

- python: '3.13-dev'
env:

- python: 'pypy3.8-7.3.9' # at 7.3.11
env:

- python: 'pypy3.9-7.3.9' # at 7.3.12
- python: 'pypy3.9-7.3.9' # at 7.3.13
env:

- python: 'pypy3.10-7.3.12'
- python: 'pypy3.10-7.3.13'
env:

allow_failures:
- python: '3.12-dev'
- python: 'pypy3.10-7.3.12' # CI missing
- python: '3.13-dev'
- python: 'pypy3.10-7.3.13' # CI missing
fast_finish: true

cache:
Expand Down
4 changes: 3 additions & 1 deletion dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,9 +2018,11 @@ def save_function(pickler, obj):
_PyCapsule_SetName.argtypes = (ctypes.py_object, ctypes.c_char_p)
_PyCapsule_SetPointer = ctypes.pythonapi.PyCapsule_SetPointer
_PyCapsule_SetPointer.argtypes = (ctypes.py_object, ctypes.c_void_p)
#from _socket import CAPI as _testcapsule
_testcapsule_name = b'dill._dill._testcapsule'
_testcapsule = _PyCapsule_New(
ctypes.cast(_PyCapsule_New, ctypes.c_void_p),
ctypes.create_string_buffer(b'dill._dill._testcapsule'),
ctypes.c_char_p(_testcapsule_name),
None
)
PyCapsuleType = type(_testcapsule)
Expand Down
10 changes: 7 additions & 3 deletions dill/_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import gzip
import zipfile
import tarfile
import xdrlib
import csv
import hashlib
import hmac
Expand Down Expand Up @@ -110,7 +109,10 @@ class _Struct(ctypes.Structure):
pass
_Struct._fields_ = [("_field", ctypes.c_int),("next", ctypes.POINTER(_Struct))]
_filedescrip, _tempfile = tempfile.mkstemp('r') # deleted in cleanup
_tmpf = tempfile.TemporaryFile('w')
if sys.hexversion < 0x30d00a1:
_tmpf = tempfile.TemporaryFile('w') # emits OSError 9 in python 3.13
else:
_tmpf = tempfile.NamedTemporaryFile('w').file # for > python 3.9

# objects used by dill for type declaration
registered = d = {}
Expand Down Expand Up @@ -313,7 +315,9 @@ class _Struct(ctypes.Structure):
a['TarFileType'] = tarfile.open(fileobj=_fileW,mode='w')
# file formats (CH 13)
x['DialectType'] = csv.get_dialect('excel')
a['PackerType'] = xdrlib.Packer()
if sys.hexversion < 0x30d00a1:
import xdrlib
a['PackerType'] = xdrlib.Packer()
# optional operating system services (CH 16)
a['LockType'] = threading.Lock()
a['RLockType'] = threading.RLock()
Expand Down
2 changes: 1 addition & 1 deletion dill/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def nestedglobals(func, recurse=True):
if '_GLOBAL' in line:
name = line.split('(')[-1].split(')')[0]
if CAN_NULL:
names.add(name.replace('NULL + ', ''))
names.add(name.replace('NULL + ', '').replace(' + NULL', ''))
else:
names.add(name)
for co in getattr(func, 'co_consts', tuple()):
Expand Down
14 changes: 7 additions & 7 deletions dill/tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _method(self):
special['UnboundMethodType'] = _class._method
objects.update(special)

def pickles(name, exact=False):
def pickles(name, exact=False, verbose=True):
"""quick check if object pickles with dill"""
obj = objects[name]
try:
Expand All @@ -45,19 +45,19 @@ def pickles(name, exact=False):
assert pik == obj
except AssertionError:
assert type(obj) == type(pik)
print ("weak: %s %s" % (name, type(obj)))
if verbose: print ("weak: %s %s" % (name, type(obj)))
else:
assert type(obj) == type(pik)
except Exception:
print ("fails: %s %s" % (name, type(obj)))
if verbose: print ("fails: %s %s" % (name, type(obj)))


def test_objects():
def test_objects(verbose=True):
for member in objects.keys():
#pickles(member, exact=True)
pickles(member, exact=False)
#pickles(member, exact=True, verbose=verbose)
pickles(member, exact=False, verbose=verbose)

if __name__ == '__main__':
import warnings
warnings.simplefilter('ignore')
test_objects()
test_objects(verbose=False)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Scientific/Engineering',
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ envlist =
py310
py311
py312
py313
pypy38
pypy39
pypy310
Expand Down

0 comments on commit 4b24b6d

Please sign in to comment.