Skip to content

Commit

Permalink
MAINT: remove some names from main numpy namespace (#21403)
Browse files Browse the repository at this point in the history
A small step towards numpy namespace cleanup. Removes a few names
from `__dir__` so that they are less discoverable when using
numpy interactively, e.g. in IPython or notebooks.
  • Loading branch information
rossbar committed Jun 15, 2022
1 parent 7c14383 commit 118e6c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 12 additions & 2 deletions numpy/__init__.py
Expand Up @@ -274,6 +274,7 @@
def __getattr__(attr):
# Warn for expired attributes, and return a dummy function
# that always raises an exception.
import warnings
try:
msg = __expired_functions__[attr]
except KeyError:
Expand Down Expand Up @@ -312,7 +313,11 @@ def _expired(*args, **kwds):
"{!r}".format(__name__, attr))

def __dir__():
return list(globals().keys() | {'Tester', 'testing'})
public_symbols = globals().keys() | {'Tester', 'testing'}
public_symbols -= {
"core", "matrixlib",
}
return list(public_symbols)

# Pytest testing
from numpy._pytesttester import PytestTester
Expand Down Expand Up @@ -358,7 +363,6 @@ def _mac_os_check():
except ValueError:
pass

import sys
if sys.platform == "darwin":
with warnings.catch_warnings(record=True) as w:
_mac_os_check()
Expand Down Expand Up @@ -414,6 +418,12 @@ def _pyinstaller_hooks_dir():
from pathlib import Path
return [str(Path(__file__).with_name("_pyinstaller").resolve())]

# Remove symbols imported for internal use
del os


# get the version using versioneer
from .version import __version__, git_revision as __git_version__

# Remove symbols imported for internal use
del sys, warnings

This comment has been minimized.

Copy link
@karna48

karna48 Mar 3, 2023

breaks pyclustering library:
annoviko/pyclustering#696

1 change: 0 additions & 1 deletion numpy/__init__.pyi
Expand Up @@ -203,7 +203,6 @@ from numpy import (
lib as lib,
linalg as linalg,
ma as ma,
matrixlib as matrixlib,
polynomial as polynomial,
random as random,
testing as testing,
Expand Down

0 comments on commit 118e6c4

Please sign in to comment.