diff --git a/cloudpickle/cloudpickle_fast.py b/cloudpickle/cloudpickle_fast.py index 70b5ecec..99522a7f 100644 --- a/cloudpickle/cloudpickle_fast.py +++ b/cloudpickle/cloudpickle_fast.py @@ -244,7 +244,23 @@ def _enum_getstate(obj): def _code_reduce(obj): """codeobject reducer""" - if hasattr(obj, "co_linetable"): # pragma: no branch + # If you are not sure about the order of arguments, take a look at help + # of the specific type from types, for example: + # >>> from types import CodeType + # >>> help(CodeType) + if hasattr(obj, "co_columntable"): # pragma: no branch + # Python 3.11 and later: there are some new attributes + # related to the enhanced exceptions. + args = ( + obj.co_argcount, obj.co_posonlyargcount, + obj.co_kwonlyargcount, obj.co_nlocals, obj.co_stacksize, + obj.co_flags, obj.co_code, obj.co_consts, obj.co_names, + obj.co_varnames, obj.co_filename, obj.co_name, obj.co_qualname, + obj.co_firstlineno, obj.co_linetable, obj.co_endlinetable, + obj.co_columntable, obj.co_exceptiontable, obj.co_freevars, + obj.co_cellvars, + ) + elif hasattr(obj, "co_linetable"): # pragma: no branch # Python 3.10 and later: obj.co_lnotab is deprecated and constructor # expects obj.co_linetable instead. args = ( diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py index 181a859e..c56e7e8c 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -2386,29 +2386,13 @@ def method(self, arg: type_) -> type_: def check_annotations(obj, expected_type, expected_type_str): assert obj.__annotations__["attribute"] == expected_type - if sys.version_info >= (3, 11): - # In Python 3.11, type annotations are stored as strings. - # See PEP 563 for more details: - # https://www.python.org/dev/peps/pep-0563/ - # Originaly scheduled for 3.10, then postponed. - # See this for more details: - # https://mail.python.org/archives/list/python-dev@python.org/thread/CLVXXPQ2T2LQ5MP2Y53VVQFCXYWQJHKZ/ - assert ( - obj.method.__annotations__["arg"] - == expected_type_str - ) - assert ( - obj.method.__annotations__["return"] - == expected_type_str - ) - else: - assert ( - obj.method.__annotations__["arg"] == expected_type - ) - assert ( - obj.method.__annotations__["return"] - == expected_type - ) + assert ( + obj.method.__annotations__["arg"] == expected_type + ) + assert ( + obj.method.__annotations__["return"] + == expected_type + ) return "ok" obj = MyClass() diff --git a/tox.ini b/tox.ini index e1ae336b..f7d28f0c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35, py36, py37, py38, py39, py310, pypy3 +envlist = py35, py36, py37, py38, py39, py310, py311, pypy3 [testenv] deps = -rdev-requirements.txt