Skip to content

Commit

Permalink
Import ABC from collections.abc (#983)
Browse files Browse the repository at this point in the history
Use compatibility layer for Python 2 support
  • Loading branch information
tirkarthi authored Jul 16, 2020
1 parent 058cb87 commit 165ba41
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 1 addition & 2 deletions meshroom/core/attribute.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# coding:utf-8
import collections
import copy
import re
import weakref
Expand Down Expand Up @@ -203,7 +202,7 @@ def getExportValue(self):

def getValueStr(self):
if isinstance(self.attributeDesc, desc.ChoiceParam) and not self.attributeDesc.exclusive:
assert(isinstance(self.value, collections.Sequence) and not isinstance(self.value, pyCompatibility.basestring))
assert(isinstance(self.value, pyCompatibility.Sequence) and not isinstance(self.value, pyCompatibility.basestring))
return self.attributeDesc.joinChar.join(self.value)
if isinstance(self.attributeDesc, (desc.StringParam, desc.File)):
return '"{}"'.format(self.value)
Expand Down
3 changes: 1 addition & 2 deletions meshroom/core/desc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from meshroom.common import BaseObject, Property, Variant, VariantList
from meshroom.core import pyCompatibility
from enum import Enum # available by default in python3. For python2: "pip install enum34"
import collections
import math
import os
import psutil
Expand Down Expand Up @@ -230,7 +229,7 @@ def validateValue(self, value):
if self.exclusive:
return self.conformValue(value)

if not isinstance(value, collections.Iterable):
if not isinstance(value, pyCompatibility.Iterable):
raise ValueError('Non exclusive ChoiceParam value should be iterable (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))
return [self.conformValue(v) for v in value]

Expand Down
7 changes: 7 additions & 0 deletions meshroom/core/pyCompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@
unicode = unicode
bytes = str
basestring = basestring

try:
# Import ABC from collections.abc in Python 3.4+
from collections.abc import Sequence, Iterable
except ImportError:
# Import ABC from collections in Python 2 support
from collections import Sequence, Iterable

0 comments on commit 165ba41

Please sign in to comment.