Skip to content

Commit d7ca480

Browse files
larsonerjnothman
authored andcommitted
MNT Fix collections.abc imports (#195)
1 parent 2ab437d commit d7ca480

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

numpydoc/docscrape.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
import re
99
import pydoc
1010
from warnings import warn
11-
import collections
11+
from collections import namedtuple
12+
try:
13+
from collections.abc import Callable, Mapping
14+
except ImportError:
15+
from collections import Callable, Mapping
1216
import copy
1317
import sys
1418

@@ -106,10 +110,10 @@ def __str__(self):
106110
return message
107111

108112

109-
Parameter = collections.namedtuple('Parameter', ['name', 'type', 'desc'])
113+
Parameter = namedtuple('Parameter', ['name', 'type', 'desc'])
110114

111115

112-
class NumpyDocString(collections.Mapping):
116+
class NumpyDocString(Mapping):
113117
"""Parses a numpydoc string to an abstract representation
114118
115119
Instances define a mapping from section title to structured data.
@@ -607,7 +611,7 @@ def methods(self):
607611
return [name for name, func in inspect.getmembers(self._cls)
608612
if ((not name.startswith('_')
609613
or name in self.extra_public_methods)
610-
and isinstance(func, collections.Callable)
614+
and isinstance(func, Callable)
611615
and self._is_show_member(name))]
612616

613617
@property

numpydoc/docscrape_sphinx.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import inspect
66
import textwrap
77
import pydoc
8-
import collections
8+
try:
9+
from collections.abc import Callable
10+
except ImportError:
11+
from collections import Callable
912
import os
1013

1114
from jinja2 import FileSystemLoader
@@ -413,7 +416,7 @@ def get_doc_object(obj, what=None, doc=None, config={}, builder=None):
413416
what = 'class'
414417
elif inspect.ismodule(obj):
415418
what = 'module'
416-
elif isinstance(obj, collections.Callable):
419+
elif isinstance(obj, Callable):
417420
what = 'function'
418421
else:
419422
what = 'object'

numpydoc/numpydoc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
import re
2323
import pydoc
2424
import inspect
25-
import collections
25+
try:
26+
from collections.abc import Callable
27+
except ImportError:
28+
from collections import Callable
2629
import hashlib
2730

2831
from docutils.nodes import citation, Text
@@ -156,7 +159,7 @@ def mangle_signature(app, what, name, obj, options, sig, retann):
156159
'initializes x; see ' in pydoc.getdoc(obj.__init__))):
157160
return '', ''
158161

159-
if not (isinstance(obj, collections.Callable) or
162+
if not (isinstance(obj, Callable) or
160163
hasattr(obj, '__argspec_is_invalid_')):
161164
return
162165

0 commit comments

Comments
 (0)