Skip to content

Commit

Permalink
Merge pull request #430 from neutrinoceros/auto_filter_depr
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros authored Jul 22, 2023
2 parents e4f16bb + 0964503 commit b0ff846
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/bleeding-edge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ jobs:

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade setuptools wheel setuptools_scm
python3 -m pip install git+https://github.com/numpy/numpy.git
python3 -m pip install git+https://github.com/matplotlib/matplotlib.git
python3 -m pip install pytest
python3 -m pip install --pre sympy
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools wheel setuptools_scm
python -m pip install --pre --extra-index \
https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy matplotlib
python -m pip install pytest
python -m pip install --pre sympy
- name: Build unyt
run: python3 -m pip install --no-build-isolation .
run: python -m pip install --no-build-isolation .

- name: Run Tests
run: pytest -vvv unyt/
37 changes: 36 additions & 1 deletion unyt/tests/test_array_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,37 @@
NOT_HANDLED_FUNCTIONS.add(getattr(np, func))


def get_decorators(func):
# adapted from
# https://stackoverflow.com/questions/3232024/introspection-to-get-decorator-names-on-a-method
import ast
import inspect

target = func
decorators = {}

def visit_FunctionDef(node):
decorators[node.name] = []
for n in node.decorator_list:
name = ""
if isinstance(n, ast.Call):
name = n.func.attr if isinstance(n.func, ast.Attribute) else n.func.id
else:
name = n.attr if isinstance(n, ast.Attribute) else n.id

decorators[node.name].append(name)

node_iter = ast.NodeVisitor()
node_iter.visit_FunctionDef = visit_FunctionDef
try:
node_iter.visit(ast.parse(inspect.getsource(target)))
return decorators[func.__name__]
except TypeError:
# may be raised if inspecting a C compiled function
# in which case, we return with empty hands
return []


def get_wrapped_functions(*modules):
"""get functions that support __array_function__ in modules
Expand All @@ -194,7 +225,11 @@ def get_wrapped_functions(*modules):
for mod in modules:
for name, f in mod.__dict__.items():
if callable(f) and hasattr(f, "__wrapped__"):
if f is np.printoptions or f.__name__.startswith("_"):
if (
f is np.printoptions
or f.__name__.startswith("_")
or "deprecate" in get_decorators(f)
):
continue
wrapped_functions[mod.__name__ + "." + name] = f
return dict(sorted(wrapped_functions.items()))
Expand Down

0 comments on commit b0ff846

Please sign in to comment.