summaryrefslogtreecommitdiff
path: root/networkx/utils
diff options
context:
space:
mode:
authorRoss Barnowski <rossbar@berkeley.edu>2021-11-17 21:12:56 -0800
committerGitHub <noreply@github.com>2021-11-17 21:12:56 -0800
commit00c261f951ae6734001e0419d2bc754eef6dd1b2 (patch)
tree54e6ce86c89f3de9f2d960f4726025487216d3c8 /networkx/utils
parent4ebdb5e2ca6c6a1f9fb3bf8c2279f9b857c6d8a7 (diff)
downloadnetworkx-00c261f951ae6734001e0419d2bc754eef6dd1b2.tar.gz
Add Mypy type checking infrastructure (#5127)
* Add minimal mypy configuration file. * Add mypy workflow to GH. * Properly import sentinels from traversal.edgedfs. * mypy doesn't like variables named \"e\". * Rm annotations from single function. * Fix name collisions in test suite. Make sure all tests have unique names. * Rm unused random seed in test setup. * Rm redundant __all__ specification. * Silence mypy error from sum(). Mypy bug? * Fix tsp test instantiation nit. * \"type: ignore\" to suppress conditional fn sigature errors. * Remaining \"type: ignore\" to appease mypy. * Configure mypy to ignore inheritance issues. * Update exclude conf for CI. - Add yaml - Reformat regex containing reportviews * Rm partial annotations from lukes.py. Fixes mypy errors due to unannotated code. * Reorg defaultdict to reduce type: ignore cruft. * Homogenize signatures for fns defined in conditionals. * err as varname only in exception catching. * Fix name collision in Bellman-Ford test suite.
Diffstat (limited to 'networkx/utils')
-rw-r--r--networkx/utils/decorators.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/networkx/utils/decorators.py b/networkx/utils/decorators.py
index 14bac852..e8e4bff5 100644
--- a/networkx/utils/decorators.py
+++ b/networkx/utils/decorators.py
@@ -92,10 +92,12 @@ def not_implemented_for(*graph_types):
# To handle new extensions, define a function accepting a `path` and `mode`.
# Then add the extension to _dispatch_dict.
-_dispatch_dict = defaultdict(lambda: open)
-_dispatch_dict[".gz"] = gzip.open
-_dispatch_dict[".bz2"] = bz2.BZ2File
-_dispatch_dict[".gzip"] = gzip.open
+fopeners = {
+ ".gz": gzip.open,
+ ".gzip": gzip.open,
+ ".bz2": bz2.BZ2File,
+}
+_dispatch_dict = defaultdict(lambda: open, **fopeners) # type: ignore
def open_file(path_arg, mode="r"):