diff options
author | lucaszhao19 | 2020-02-05 18:02:20 +0530 |
---|---|---|
committer | lucaszhao19 | 2020-02-05 18:02:20 +0530 |
commit | ae7090629a8beae3064eee7128856d5d3aeaa604 (patch) | |
tree | 939eedc5d96fd17bc5af34bde6524d3e4b3a7cfa /venv/Lib/site-packages/astroid/brain/brain_numpy_utils.py | |
parent | 38dbff48f57c403abdc575a9cd9d0bbf512bfef6 (diff) | |
parent | 190966e010e321e4df56d40104ec80467a870e53 (diff) | |
download | Chemical-Simulator-GUI-ae7090629a8beae3064eee7128856d5d3aeaa604.tar.gz Chemical-Simulator-GUI-ae7090629a8beae3064eee7128856d5d3aeaa604.tar.bz2 Chemical-Simulator-GUI-ae7090629a8beae3064eee7128856d5d3aeaa604.zip |
Revamped and merged Input/Results DockWidgets, Newly implemented variables for MaterialStream and four UnitOps
Diffstat (limited to 'venv/Lib/site-packages/astroid/brain/brain_numpy_utils.py')
-rw-r--r-- | venv/Lib/site-packages/astroid/brain/brain_numpy_utils.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/venv/Lib/site-packages/astroid/brain/brain_numpy_utils.py b/venv/Lib/site-packages/astroid/brain/brain_numpy_utils.py new file mode 100644 index 0000000..2bad01e --- /dev/null +++ b/venv/Lib/site-packages/astroid/brain/brain_numpy_utils.py @@ -0,0 +1,56 @@ +# Copyright (c) 2018-2019 hippo91 <guillaume.peillex@gmail.com> + +# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html +# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER + + +"""Different utilities for the numpy brains""" + + +import astroid + + +def infer_numpy_member(src, node, context=None): + node = astroid.extract_node(src) + return node.infer(context=context) + + +def _is_a_numpy_module(node: astroid.node_classes.Name) -> bool: + """ + Returns True if the node is a representation of a numpy module. + + For example in : + import numpy as np + x = np.linspace(1, 2) + The node <Name.np> is a representation of the numpy module. + + :param node: node to test + :return: True if the node is a representation of the numpy module. + """ + module_nickname = node.name + potential_import_target = [ + x for x in node.lookup(module_nickname)[1] if isinstance(x, astroid.Import) + ] + for target in potential_import_target: + if ("numpy", module_nickname) in target.names: + return True + return False + + +def looks_like_numpy_member( + member_name: str, node: astroid.node_classes.NodeNG +) -> bool: + """ + Returns True if the node is a member of numpy whose + name is member_name. + + :param member_name: name of the member + :param node: node to test + :return: True if the node is a member of numpy + """ + return ( + isinstance(node, astroid.Attribute) + and node.attrname == member_name + and isinstance(node.expr, astroid.Name) + and _is_a_numpy_module(node.expr) + ) |