Skip to content

Commit

Permalink
Make find_callname only lookup functions that are likely part of NumPy.
Browse files Browse the repository at this point in the history
As title.

Closes numba#6175
  • Loading branch information
stuartarchibald committed Sep 2, 2020
1 parent d58a63a commit 2a98141
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions numba/core/ir_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ def find_callname(func_ir, expr, typemap=None, definition_finder=get_definition)
if isinstance(callee_def, (ir.Global, ir.FreeVar)):
# require(callee_def.value == numpy)
# these checks support modules like numpy, numpy.random as well as
# calls like len() and intrinsitcs like assertEquiv
# calls like len() and intrinsics like assertEquiv
keys = ['name', '_name', '__name__']
value = None
for key in keys:
Expand All @@ -1521,8 +1521,15 @@ def find_callname(func_ir, expr, typemap=None, definition_finder=get_definition)
def_val = def_val._defn
if hasattr(def_val, '__module__'):
mod_name = def_val.__module__
# The reason for first checking if the function is in NumPy's
# top level name space by module is that some functions are
# deprecated in NumPy but the functions' names are aliased with
# other common names. This prevents deprecation warnings on
# e.g. getattr(numpy, 'bool') were a bool the the target.
# For context see #6175, impacts NumPy>=1.20.
numpy_toplevel = mod_name == 'numpy'
# it might be a numpy function imported directly
if (hasattr(numpy, value)
if (numpy_toplevel and hasattr(numpy, value)
and def_val == getattr(numpy, value)):
attrs += ['numpy']
# it might be a np.random function imported directly
Expand Down

0 comments on commit 2a98141

Please sign in to comment.