Skip to content

Commit

Permalink
Python 3 deprecation fixes (including Preparing for Python 3.9) (Acad…
Browse files Browse the repository at this point in the history
…emySoftwareFoundation#820)

* Added import aliasing for collections.abc module for python 3.9 support
* Created local alias for inspect.getargspec to address python 3+ deprecation warning
* Updated mutable sequence bindings to expose __next__ in compliance with PEP 3114.
* Updated collections.abc rename behavior to match six's and use collections_abc.
* Added python 3.9 to CI builds, updated python badge to match our CI builds - added 3.9 and corrected it still having 3.6 and missing 3.8.
* Updated the python 2/3 compatibility on the inspect.getargspec to match the python 3 naming rather than python 2.
* Removed python 3.9 from CI. See AcademySoftwareFoundation#828 for more context about the Python 3.9.0/pybind11 bug.
  • Loading branch information
reinecke committed Oct 30, 2020
1 parent 1b16826 commit 44f8ce8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OpenTimelineIO
==============

[![Supported VFX Platform Versions](https://img.shields.io/badge/vfx%20platform-2016--2020-lightgrey.svg)](http://www.vfxplatform.com/)
![Supported Versions](https://img.shields.io/badge/python-2.7%2C%203.6%2C%203.7-blue.svg)
![Supported Versions](https://img.shields.io/badge/python-2.7%2C%203.7%2C%203.8-blue.svg)
[![Build Status](https://travis-ci.com/PixarAnimationStudios/OpenTimelineIO.svg?branch=master)](https://travis-ci.com/PixarAnimationStudios/OpenTimelineIO)
[![codecov](https://codecov.io/gh/PixarAnimationStudios/OpenTimelineIO/branch/master/graph/badge.svg)](https://codecov.io/gh/PixarAnimationStudios/OpenTimelineIO)
[![docs](https://readthedocs.org/projects/opentimelineio/badge/?version=latest)](https://opentimelineio.readthedocs.io/en/latest/index.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
import sys
import numbers
import copy
import collections
try:
# Python 3.3+
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
import fractions
import opentimelineio as otio

Expand Down Expand Up @@ -552,7 +556,7 @@ def _transcribe(item, parents, edit_rate, indent=0):
# elif isinstance(item, pyaaf.AxProperty):
# self.properties['Value'] = str(item.GetValue())

elif isinstance(item, collections.Iterable):
elif isinstance(item, collections_abc.Iterable):
msg = "Creating SerializableCollection for Iterable for {}".format(
_encoded_name(item))
_transcribe_log(msg, indent)
Expand Down
3 changes: 2 additions & 1 deletion src/py-opentimelineio/opentimelineio-bindings/otio_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ struct MutableSequencePyAPI : public V {

pybind11::class_<This::Iterator>(m, (name + "Iterator").c_str())
.def("__iter__", &This::Iterator::iter)
.def("next", &This::Iterator::next);
.def("next", &This::Iterator::next)
.def("__next__", &This::Iterator::next);

pybind11::class_<This>(m, name.c_str())
.def(pybind11::init<>())
Expand Down
9 changes: 8 additions & 1 deletion src/py-opentimelineio/opentimelineio/adapters/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
)


try:
# Python 3.0+
getfullargspec = inspect.getfullargspec
except AttributeError:
getfullargspec = inspect.getargspec


@core.register_type
class Adapter(plugins.PythonPlugin):
"""Adapters convert between OTIO and other formats.
Expand Down Expand Up @@ -307,7 +314,7 @@ def plugin_info_map(self):
for fn_name in _FEATURE_MAP[feature]:
if hasattr(self.module(), fn_name):
fn = getattr(self.module(), fn_name)
args = inspect.getargspec(fn)
args = getfullargspec(fn)
docs = inspect.getdoc(fn)
break

Expand Down
26 changes: 15 additions & 11 deletions src/py-opentimelineio/opentimelineio/core/_core_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import types
import collections
try:
# Python 3.3+
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
import copy
import sys

Expand Down Expand Up @@ -46,7 +50,7 @@ def _xrange(*args):


def _is_nonstring_sequence(v):
return isinstance(v, collections.Sequence) and not _is_str(v)
return isinstance(v, collections_abc.Sequence) and not _is_str(v)


def _value_to_any(value, ids=None):
Expand All @@ -55,7 +59,7 @@ def _value_to_any(value, ids=None):

if isinstance(value, SerializableObject):
return PyAny(value)
if isinstance(value, collections.Mapping):
if isinstance(value, collections_abc.Mapping):
if ids is None:
ids = set()
d = AnyDictionary()
Expand Down Expand Up @@ -88,7 +92,7 @@ def _value_to_any(value, ids=None):


def _value_to_so_vector(value, ids=None):
if not isinstance(value, collections.Sequence) or _is_str(value):
if not isinstance(value, collections_abc.Sequence) or _is_str(value):
raise TypeError(
"Expected list/sequence of SerializableObjects;"
" found type '{}'".format(type(value))
Expand Down Expand Up @@ -150,13 +154,13 @@ def __deepcopy__(self, memo):
)
return m

collections.MutableMapping.register(mapClass)
collections_abc.MutableMapping.register(mapClass)
mapClass.__setitem__ = __setitem__
mapClass.__str__ = __str__
mapClass.__repr__ = __repr__

seen = set()
for klass in (collections.MutableMapping, collections.Mapping):
for klass in (collections_abc.MutableMapping, collections_abc.Mapping):
for name in klass.__dict__.keys():
if name in seen:
continue
Expand Down Expand Up @@ -217,15 +221,15 @@ def __setitem__(self, index, item):
if not isinstance(index, slice):
self.__internal_setitem__(index, conversion_func(item))
else:
if not isinstance(item, collections.Iterable):
if not isinstance(item, collections_abc.Iterable):
raise TypeError("can only assign an iterable")

indices = range(*index.indices(len(self)))

if index.step in (1, None):
if (
not side_effecting_insertions
and isinstance(item, collections.MutableSequence)
and isinstance(item, collections_abc.MutableSequence)
and len(item) == len(indices)
):
for i0, i in enumerate(indices):
Expand Down Expand Up @@ -254,7 +258,7 @@ def __setitem__(self, index, item):
self.extend(cached_items)
raise e
else:
if not isinstance(item, collections.Sequence):
if not isinstance(item, collections_abc.Sequence):
raise TypeError("can only assign a sequence")
if len(item) != len(indices):
raise ValueError(
Expand Down Expand Up @@ -292,7 +296,7 @@ def insert(self, index, item):
if conversion_func else item
)

collections.MutableSequence.register(sequenceClass)
collections_abc.MutableSequence.register(sequenceClass)
sequenceClass.__radd__ = __radd__
sequenceClass.__add__ = __add__
sequenceClass.__getitem__ = __getitem__
Expand All @@ -303,7 +307,7 @@ def insert(self, index, item):
sequenceClass.__repr__ = __repr__

seen = set()
for klass in (collections.MutableSequence, collections.Sequence):
for klass in (collections_abc.MutableSequence, collections_abc.Sequence):
for name in klass.__dict__.keys():
if name not in seen:
seen.add(name)
Expand Down

0 comments on commit 44f8ce8

Please sign in to comment.