diff options
| author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-19 13:05:56 +0200 |
|---|---|---|
| committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-08-11 09:18:18 +0200 |
| commit | fe69256a44e9744d97fb73baab0d3d9b238c095b (patch) | |
| tree | 8385397859f7e2fcf00d518efb3c7c190734bd80 /astroid | |
| parent | 3526320cb3bfdd58b33c90ca5bf6adc2c7ea24c9 (diff) | |
| download | astroid-git-fe69256a44e9744d97fb73baab0d3d9b238c095b.tar.gz | |
Create a astroid.nodes.const file for constants
Diffstat (limited to 'astroid')
| -rw-r--r-- | astroid/nodes/const.py | 27 | ||||
| -rw-r--r-- | astroid/nodes/node_classes.py | 31 |
2 files changed, 30 insertions, 28 deletions
diff --git a/astroid/nodes/const.py b/astroid/nodes/const.py new file mode 100644 index 00000000..8f1b6abd --- /dev/null +++ b/astroid/nodes/const.py @@ -0,0 +1,27 @@ +# 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/LICENSE + + +OP_PRECEDENCE = { + op: precedence + for precedence, ops in enumerate( + [ + ["Lambda"], # lambda x: x + 1 + ["IfExp"], # 1 if True else 2 + ["or"], + ["and"], + ["not"], + ["Compare"], # in, not in, is, is not, <, <=, >, >=, !=, == + ["|"], + ["^"], + ["&"], + ["<<", ">>"], + ["+", "-"], + ["*", "@", "/", "//", "%"], + ["UnaryOp"], # +, -, ~ + ["**"], + ["Await"], + ] + ) + for op in ops +} diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index e087b91b..fed043bd 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -57,6 +57,7 @@ from astroid.exceptions import ( UseInferenceDefault, ) from astroid.manager import AstroidManager +from astroid.nodes.const import OP_PRECEDENCE if sys.version_info >= (3, 8): from typing import Literal @@ -241,31 +242,6 @@ def _container_getitem(instance, elts, index, context=None): raise AstroidTypeError("Could not use %s as subscript index" % index) -OP_PRECEDENCE = { - op: precedence - for precedence, ops in enumerate( - [ - ["Lambda"], # lambda x: x + 1 - ["IfExp"], # 1 if True else 2 - ["or"], - ["and"], - ["not"], - ["Compare"], # in, not in, is, is not, <, <=, >, >=, !=, == - ["|"], - ["^"], - ["&"], - ["<<", ">>"], - ["+", "-"], - ["*", "@", "/", "//", "%"], - ["UnaryOp"], # +, -, ~ - ["**"], - ["Await"], - ] - ) - for op in ops -} - - class NodeNG: """A node of the new Abstract Syntax Tree (AST). @@ -451,7 +427,7 @@ class NodeNG: yield attr yield from () - def last_child(self): # -> Optional["NodeNG"] + def last_child(self) -> Optional["NodeNG"]: """An optimized version of list(get_children())[-1]""" for field in self._astroid_fields[::-1]: attr = getattr(self, field) @@ -611,8 +587,7 @@ class NodeNG: last_child = self.last_child() if last_child is None: return self.fromlineno - - return last_child.tolineno + return last_child.tolineno # pylint: disable=no-member def _fixed_source_line(self) -> Optional[int]: """Attempt to find the line that this node appears on. |
