summaryrefslogtreecommitdiff
path: root/networkx/utils
diff options
context:
space:
mode:
authorRoss Barnowski <rossbar@berkeley.edu>2021-04-25 10:26:49 -0700
committerGitHub <noreply@github.com>2021-04-25 13:26:49 -0400
commit4a8210c14643b001cf1f97d32892c2c4134bc5a0 (patch)
tree8478b43affd804f0b7b3ed43fb01c01bc7f3f9d8 /networkx/utils
parent63f550fef6712d5ea3ae09bbc341d696d65e55e3 (diff)
downloadnetworkx-4a8210c14643b001cf1f97d32892c2c4134bc5a0.tar.gz
Add missing __all__'s to utils modules + test. (#4753)
Adds __all__ attrs to modules in utils and adds a test to ensure objects and aliases defined in utils modules are not unintentionally exposed in the utils namespace.
Diffstat (limited to 'networkx/utils')
-rw-r--r--networkx/utils/misc.py24
-rw-r--r--networkx/utils/random_sequence.py10
-rw-r--r--networkx/utils/tests/test__init.py11
3 files changed, 45 insertions, 0 deletions
diff --git a/networkx/utils/misc.py b/networkx/utils/misc.py
index 4caffbe1..bd58a4ed 100644
--- a/networkx/utils/misc.py
+++ b/networkx/utils/misc.py
@@ -19,6 +19,30 @@ import uuid
from itertools import tee, chain
import networkx as nx
+__all__ = [
+ "is_string_like",
+ "iterable",
+ "empty_generator",
+ "flatten",
+ "make_list_of_ints",
+ "is_list_of_ints",
+ "make_str",
+ "generate_unique_node",
+ "default_opener",
+ "dict_to_numpy_array",
+ "dict_to_numpy_array1",
+ "dict_to_numpy_array2",
+ "is_iterator",
+ "arbitrary_element",
+ "consume",
+ "pairwise",
+ "groups",
+ "to_tuple",
+ "create_random_state",
+ "create_py_random_state",
+ "PythonRandomInterface",
+]
+
# some cookbook stuff
# used in deciding whether something is a bunch of nodes, edges, etc.
diff --git a/networkx/utils/random_sequence.py b/networkx/utils/random_sequence.py
index 7bd68c79..ad9b34a3 100644
--- a/networkx/utils/random_sequence.py
+++ b/networkx/utils/random_sequence.py
@@ -7,6 +7,16 @@ import networkx as nx
from networkx.utils import py_random_state
+__all__ = [
+ "powerlaw_sequence",
+ "zipf_rv",
+ "cumulative_distribution",
+ "discrete_sequence",
+ "random_weighted_sample",
+ "weighted_choice",
+]
+
+
# The same helpers for choosing random sequences from distributions
# uses Python's random module
# https://docs.python.org/3/library/random.html
diff --git a/networkx/utils/tests/test__init.py b/networkx/utils/tests/test__init.py
new file mode 100644
index 00000000..ecbcce36
--- /dev/null
+++ b/networkx/utils/tests/test__init.py
@@ -0,0 +1,11 @@
+import pytest
+
+
+def test_utils_namespace():
+ """Ensure objects are not unintentionally exposed in utils namespace."""
+ with pytest.raises(ImportError):
+ from networkx.utils import nx
+ with pytest.raises(ImportError):
+ from networkx.utils import sys
+ with pytest.raises(ImportError):
+ from networkx.utils import defaultdict, deque