Skip to content

Commit

Permalink
MAINT: Revise imports from collections.abc module
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Jan 22, 2020
1 parent e94cec8 commit 1bc1fd6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 53 deletions.
12 changes: 5 additions & 7 deletions doc/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
"""
import os, glob, re, sys, inspect, optparse
try:
# Accessing collections abstract classes from collections
# has been deprecated since Python 3.3
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
import collections.abc

sys.path.append(os.path.join(os.path.dirname(__file__), 'sphinxext'))
from sphinxext.phantom_import import import_phantom_module

Expand Down Expand Up @@ -139,7 +135,9 @@ def get_undocumented(documented, module, module_name=None, skip=[]):

if full_name in skip: continue
if full_name.startswith('numpy.') and full_name[6:] in skip: continue
if not (inspect.ismodule(obj) or isinstance(obj, collections_abc.Callable) or inspect.isclass(obj)):
if not (inspect.ismodule(obj) or
isinstance(obj, collections.abc.Callable) or
inspect.isclass(obj)):
continue

if full_name not in documented:
Expand Down
12 changes: 4 additions & 8 deletions numpy/core/_ufunc_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
This provides helpers which wrap `umath.geterrobj` and `umath.seterrobj`
"""
try:
# Accessing collections abstract classes from collections
# has been deprecated since Python 3.3
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
import collections.abc
import contextlib

from .overrides import set_module
Expand Down Expand Up @@ -307,8 +302,9 @@ def seterrcall(func):
OrderedDict([('divide', 'log'), ('invalid', 'log'), ('over', 'log'), ('under', 'log')])
"""
if func is not None and not isinstance(func, collections_abc.Callable):
if not hasattr(func, 'write') or not isinstance(func.write, collections_abc.Callable):
if func is not None and not isinstance(func, collections.abc.Callable):
if (not hasattr(func, 'write') or
not isinstance(func.write, collections.abc.Callable)):
raise ValueError("Only callable can be used as callback")
pyvals = umath.geterrobj()
old = geterrcall()
Expand Down
9 changes: 2 additions & 7 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
try:
# Accessing collections abstract classes from collections
# has been deprecated since Python 3.3
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
import collections.abc
import tempfile
import sys
import shutil
Expand Down Expand Up @@ -7756,7 +7751,7 @@ def test_arrays_not_hashable(self):

def test_collections_hashable(self):
x = np.array([])
assert_(not isinstance(x, collections_abc.Hashable))
assert_(not isinstance(x, collections.abc.Hashable))


class TestArrayPriority:
Expand Down
10 changes: 2 additions & 8 deletions numpy/core/tests/test_records.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import sys
try:
# Accessing collections abstract classes from collections
# has been deprecated since Python 3.3
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
import collections.abc
import textwrap
from os import path
import pytest
Expand Down Expand Up @@ -252,7 +246,7 @@ def test_recarray_conflict_fields(self):
assert_array_equal(ra['shape'], [['A', 'B', 'C']])
ra.field = 5
assert_array_equal(ra['field'], [[5, 5, 5]])
assert_(isinstance(ra.field, collections_abc.Callable))
assert_(isinstance(ra.field, collections.abc.Callable))

def test_fromrecords_with_explicit_dtype(self):
a = np.rec.fromrecords([(1, 'a'), (2, 'bbb')],
Expand Down
9 changes: 2 additions & 7 deletions numpy/lib/function_base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
try:
# Accessing collections abstract classes from collections
# has been deprecated since Python 3.3
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
import collections.abc
import functools
import re
import sys
Expand Down Expand Up @@ -613,7 +608,7 @@ def piecewise(x, condlist, funclist, *args, **kw):
y = zeros(x.shape, x.dtype)
for k in range(n):
item = funclist[k]
if not isinstance(item, collections_abc.Callable):
if not isinstance(item, collections.abc.Callable):
y[condlist[k]] = item
else:
vals = x[condlist[k]]
Expand Down
9 changes: 2 additions & 7 deletions numpy/matrixlib/tests/test_defmatrix.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
try:
# Accessing collections abstract classes from collections
# has been deprecated since Python 3.3
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
import collections.abc

import numpy as np
from numpy import matrix, asmatrix, bmat
Expand Down Expand Up @@ -297,7 +292,7 @@ def test_instance_methods(self):
if attrib.startswith('_') or attrib in excluded_methods:
continue
f = getattr(a, attrib)
if isinstance(f, collections_abc.Callable):
if isinstance(f, collections.abc.Callable):
# reset contents of a
a.astype('f8')
a.fill(1.0)
Expand Down
13 changes: 4 additions & 9 deletions numpy/testing/_private/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
``nose.tools`` for more information.
"""
try:
# Accessing collections abstract classes from collections
# has been deprecated since Python 3.3
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
import collections.abc

from .utils import SkipTest, assert_warns, HAS_REFCOUNT

Expand Down Expand Up @@ -129,7 +124,7 @@ def skip_decorator(f):
import nose

# Allow for both boolean or callable skip conditions.
if isinstance(skip_condition, collections_abc.Callable):
if isinstance(skip_condition, collections.abc.Callable):
skip_val = lambda: skip_condition()
else:
skip_val = lambda: skip_condition
Expand Down Expand Up @@ -205,7 +200,7 @@ def knownfailureif(fail_condition, msg=None):
msg = 'Test skipped due to known failure'

# Allow for both boolean or callable known failure conditions.
if isinstance(fail_condition, collections_abc.Callable):
if isinstance(fail_condition, collections.abc.Callable):
fail_val = lambda: fail_condition()
else:
fail_val = lambda: fail_condition
Expand Down Expand Up @@ -260,7 +255,7 @@ def _deprecated_imp(*args, **kwargs):
with assert_warns(DeprecationWarning):
f(*args, **kwargs)

if isinstance(conditional, collections_abc.Callable):
if isinstance(conditional, collections.abc.Callable):
cond = conditional()
else:
cond = conditional
Expand Down

0 comments on commit 1bc1fd6

Please sign in to comment.