Skip to content
This repository has been archived by the owner on Apr 29, 2023. It is now read-only.

Update use of collections module to avoid deprecated idiom #111

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/ndfd/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pyxb.binding.datatypes as xsd
from pyxb.utils.six.moves.urllib.request import urlopen
import time
import collections
import collections.abc
import sys

# Get the next seven days forecast for two locations
Expand All @@ -32,7 +32,7 @@
source = r.head.source
print(", ".join(source.production_center.content()))
data = r.data
if isinstance(data, collections.MutableSequence):
if isinstance(data, collections.abc.MutableSequence):
data = data.pop(0)
print(data)

Expand Down
8 changes: 4 additions & 4 deletions pyxb/binding/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
inherit, and that describe the content models of those schema."""

import logging
import collections
import collections.abc
import xml.dom
import pyxb
from pyxb.utils import domutils, utility, six
Expand Down Expand Up @@ -1163,7 +1163,7 @@ def _CheckValidValue (cls, value):
raise pyxb.SimpleTypeValueError(cls, value)
value_class = cls
if issubclass(cls, STD_list):
if not isinstance(value, collections.Iterable):
if not isinstance(value, collections.abc.Iterable):
raise pyxb.SimpleTypeValueError(cls, value)
for v in value:
if not cls._ItemType._IsValidValue(v):
Expand Down Expand Up @@ -1363,7 +1363,7 @@ def _ConvertArguments_vx (cls, args, kw):
if isinstance(arg1, six.string_types):
args = (arg1.split(),) + args[1:]
arg1 = args[0]
if isinstance(arg1, collections.Iterable):
if isinstance(arg1, collections.abc.Iterable):
new_arg1 = [ cls._ValidatedItem(_v, kw) for _v in arg1 ]
args = (new_arg1,) + args[1:]
super_fn = getattr(super(STD_list, cls), '_ConvertArguments_vx', lambda *a,**kw: args)
Expand Down Expand Up @@ -1646,7 +1646,7 @@ def compatibleValue (self, value, **kw):
return self.__defaultValue
is_plural = kw.pop('is_plural', False)
if is_plural:
if not isinstance(value, collections.Iterable):
if not isinstance(value, collections.abc.Iterable):
raise pyxb.SimplePluralValueError(self.typeDefinition(), value)
return [ self.compatibleValue(_v) for _v in value ]
compValue = self.typeDefinition()._CompatibleValue(value, **kw);
Expand Down
4 changes: 2 additions & 2 deletions pyxb/binding/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,15 +796,15 @@ def __init__ (self, wildcard_declaration, xsd_location):
def __str__ (self):
return 'xs:any per %s' % (self.xsdLocation(),)

import collections
import collections.abc

# Do not inherit from list; that's obscene, and could cause problems with the
# internal assumptions made by Python. Instead delegate everything to an
# instance of list that's held internally. Inherit from the ABC that
# represents list-style data structures so we can identify both lists and
# these things which are not lists.
@pyxb.utils.utility.BackfillComparisons
class _PluralBinding (collections.MutableSequence):
class _PluralBinding (collections.abc.MutableSequence):
"""Helper for element content that supports multiple occurences.

This is an adapter for Python list. Any operation that can mutate an item
Expand Down
12 changes: 6 additions & 6 deletions tests/drivers/test-mg-sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def ToDOM (instance, tag=None):
return instance.toDOM().documentElement

import unittest
import collections
import collections.abc

class TestMGSeq (unittest.TestCase):
def setUp (self):
Expand Down Expand Up @@ -50,7 +50,7 @@ def testBasics (self):
self.assertTrue(isinstance(instance.first, sequence._ElementMap['first'].elementBinding().typeDefinition()))
self.assertTrue(isinstance(instance.second_opt, sequence._ElementMap['second_opt'].elementBinding().typeDefinition()))
self.assertTrue(isinstance(instance.third, sequence._ElementMap['third'].elementBinding().typeDefinition()))
self.assertTrue(isinstance(instance.fourth_0_2, collections.MutableSequence))
self.assertTrue(isinstance(instance.fourth_0_2, collections.abc.MutableSequence))
self.assertEqual(1, len(instance.fourth_0_2))
self.assertTrue(isinstance(instance.fourth_0_2[0], sequence._ElementMap['fourth_0_2'].elementBinding().typeDefinition()))
self.assertEqual(ToDOM(instance).toxml("utf-8"), xmld)
Expand All @@ -63,7 +63,7 @@ def testMultiplesAtEnd (self):
self.assertTrue(isinstance(instance.first, sequence._ElementMap['first'].elementBinding().typeDefinition()))
self.assertTrue(instance.second_opt is None)
self.assertTrue(isinstance(instance.third, sequence._ElementMap['third'].elementBinding().typeDefinition()))
self.assertTrue(isinstance(instance.fourth_0_2, collections.MutableSequence))
self.assertTrue(isinstance(instance.fourth_0_2, collections.abc.MutableSequence))
self.assertEqual(2, len(instance.fourth_0_2))
self.assertTrue(isinstance(instance.fourth_0_2[0], sequence._ElementMap['fourth_0_2'].elementBinding().typeDefinition()))
self.assertEqual(ToDOM(instance).toxml("utf-8"), xmld)
Expand All @@ -73,7 +73,7 @@ def testMultiplesInMiddle (self):
xmld = xmlt.encode('utf-8')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
instance = altwrapper.createFromDOM(dom.documentElement)
self.assertTrue(isinstance(instance.first, collections.MutableSequence))
self.assertTrue(isinstance(instance.first, collections.abc.MutableSequence))
self.assertEqual(1, len(instance.first))
self.assertEqual(2, len(instance.second_multi))
self.assertTrue(isinstance(instance.third, altsequence._ElementMap['third'].elementBinding().typeDefinition()))
Expand All @@ -84,7 +84,7 @@ def testMultiplesAtStart (self):
xmld = xmlt.encode('utf-8')
dom = pyxb.utils.domutils.StringToDOM(xmlt)
instance = altwrapper.createFromDOM(dom.documentElement)
self.assertTrue(isinstance(instance.first, collections.MutableSequence))
self.assertTrue(isinstance(instance.first, collections.abc.MutableSequence))
self.assertEqual(2, len(instance.first))
self.assertEqual(0, len(instance.second_multi))
self.assertTrue(isinstance(instance.third, altsequence._ElementMap['third'].elementBinding().typeDefinition()))
Expand All @@ -100,7 +100,7 @@ def testMissingInMiddle (self):
self.assertTrue(isinstance(instance.first, sequence._ElementMap['first'].elementBinding().typeDefinition()))
self.assertTrue(instance.second_opt is None)
self.assertTrue(isinstance(instance.third, sequence._ElementMap['third'].elementBinding().typeDefinition()))
self.assertTrue(isinstance(instance.fourth_0_2, collections.MutableSequence))
self.assertTrue(isinstance(instance.fourth_0_2, collections.abc.MutableSequence))
self.assertEqual(0, len(instance.fourth_0_2))
self.assertEqual(ToDOM(instance).toxml("utf-8"), xmld)

Expand Down
2 changes: 1 addition & 1 deletion tests/trac/test-trac-0069.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from pyxb.exceptions_ import *

import unittest
import collections
import collections.abc

# Pretend whoever created the schema was helpful and had normalized it
metadatadoc_type = MetadataDocument.typeDefinition()
Expand Down
6 changes: 3 additions & 3 deletions tests/trac/test-trac-0071.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from pyxb.exceptions_ import *

import unittest
import collections
import collections.abc

# Pretend whoever created the schema was helpful and had normalized it
metadatadoc_type = MetadataDocument.typeDefinition()
Expand All @@ -75,7 +75,7 @@
class TestTrac_0071 (unittest.TestCase):
def testFieldConstructor (self):
field = field_type('title', pyxb.BIND('foo', lang='ENG'), _element=field_element)
self.assertTrue(isinstance(field.value_, collections.MutableSequence))
self.assertTrue(isinstance(field.value_, collections.abc.MutableSequence))
self.assertEqual(1, len(field.value_))
self.assertTrue(isinstance(field.value_[0], value_type))
field.validateBinding()
Expand All @@ -89,7 +89,7 @@ def testFieldElementAppend (self):

field = field_type(name='title', _element=field_element)
field.value_.append(pyxb.BIND('foo', lang='ENG'))
self.assertTrue(isinstance(field.value_, collections.MutableSequence))
self.assertTrue(isinstance(field.value_, collections.abc.MutableSequence))
self.assertEqual(1, len(field.value_))
self.assertTrue(isinstance(field.value_[0], value_type))
field.validateBinding()
Expand Down