summaryrefslogtreecommitdiff
path: root/astroid/node_classes.py
Commit message (Collapse)AuthorAgeFilesLines
...
* Remove methods scheduled for removalClaudiu Popa2018-06-121-29/+0
|
* Fix the itered() for dictionariesClaudiu Popa2018-06-091-1/+1
| | | | It was skipping elements and wasn't actually doing what it was supposed to do.
* Fix typoClaudiu Popa2018-06-091-1/+1
|
* Add NoChildrenMixinNick Drozd2018-06-081-56/+16
| | | | This allows consolidating all the empty get_children methods.
* Convert to yield fromNick Drozd2018-06-081-18/+10
| | | | | | | I tried this to see if it would improve performance. It didn't, but it does look nicer, so we might as well keep it. See also 5fd5aa81483e709cb5c464c7d4bb37c8c39f2afa
* Cache lookup (#552)Nick Drozd2018-06-041-0/+2
| | | This provides a significant speedup.
* Remove reraise() in favour of using raise..fromClaudiu Popa2018-05-311-15/+13
|
* kill aliases scheduled for removalClaudiu Popa2018-05-241-11/+0
|
* Add support for type comments (#548)Claudiu Popa2018-05-231-4/+25
|
* Corrected child orderAshley Whetter2018-05-051-9/+9
| | | | | | | | | | | 52e67656d7728f8ba958c9c35bef3a44013ad6dd introduced a new type of child iteration. Some classes started yielding children in the incorrect order, which was causing test failures in pylint. This change corrects the ordering to match the _astroid_fields of the class. Relates to a change from #497
* Check against astroid_fields explicitlyClaudiu Popa2018-04-251-2/+2
|
* Verify that the names exists in _other_fields before accessing themClaudiu Popa2018-04-251-1/+4
| | | | | Some nodes such as the ExceptHandler has a name object but that is an AST node, not a string. This fix prevents a crash when trying to repr() an ExceptHandler.
* Fix StopIteration raising for python3.7 (#534)HoverHell2018-04-241-3/+3
| | | | | | Because we don't support Python 2 any longer in the master branch, we can return values from generators to signal that we want to throw a StopIteration, without actually raising the StopIteration itself.
* Add MultiLineBlockMixinNick Drozd2018-03-301-183/+18
| | | | | | | | `_multi_line_block_fields` is a list of strings indicating which fields contain multi-line blocks. `_get_multi_line_blocks` dynamically accesses these attributes the first time it is called and then caches the resulting references so as to avoid repeated expensive attribute lookups.
* Improve _get_yield_nodes_skip_lambdas algorithmNick Drozd2018-03-301-11/+72
| | | | | | Yield statements can only appear in multiline bodies (like function definitions) and in lambdas, so there is no need to check other nodes for them.
* Improve _get_return_nodes_skip_functions algorithmNick Drozd2018-03-301-11/+71
| | | | | Return statements can only appear in multiline bodies (like function definitions), so there is no need to check other nodes for them.
* Improve _get_assign_nodes algorithmNick Drozd2018-03-301-6/+41
| | | | | | | Assign statements can only appear in multiline bodies (like function definitions) and in the value side of assign statements (e.g. `b = 4` is an assign node contained in `a = b = 4`), so there is no need to check other nodes for them.
* add qname to Unknown node to avoid error in pylintBryce Guinta2018-03-261-0/+4
|
* Add name attribute to Unknown classBryce Guinta2018-03-261-0/+1
| | | | | | This allows .root().name calls to work for Unknown objects Close #523
* Revert "Move FrozenSet to node_classes so it is accessible"Bryce Guinta2018-03-111-15/+0
| | | | This reverts commit 06273cd07d4b3701998df7b2c656d1b029bdee8e.
* Move FrozenSet to node_classes so it is accessibleBryce Guinta2018-03-111-0/+15
| | | | importing astroid.objects causes curcular imports with manager
* Add type-specific nodes_of_classNick Drozd2018-03-021-2/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | nodes_of_class is a very flexible method, which is great for use in client code (e.g. Pylint). However, that flexibility requires a great deal of runtime type checking: def nodes_of_class(self, klass, skip_klass=None): if isinstance(self, klass): yield self if skip_klass is None: for child_node in self.get_children(): for matching in child_node.nodes_of_class(klass, skip_klass): yield matching return for child_node in self.get_children(): if isinstance(child_node, skip_klass): continue for matching in child_node.nodes_of_class(klass, skip_klass): yield matching First, the node has to check its own type to see whether it's of the desired class. Then the skip_klass flag has to be checked to see whether anything needs to be skipped. If so, the type of every yielded node has to be check to see if it should be skipped. This is fine for calling code whose arguments can't be known in advance ("Give me all the Assign and ClassDef nodes, but skip all the BinOps, YieldFroms, and Globals."), but in Astroid itself, every call to this function can be known in advance. There's no need to do any type checking if all the nodes know how to respond to certain requests. Take get_assign_nodes for example. The Assign nodes know that they should yield themselves and then yield their Assign children. Other nodes know in advance that they aren't Assign nodes, so they don't need to check their own type, just immediately yield their Assign children. Overly specific functions like get_yield_nodes_skip_lambdas certainly aren't very elegant, but the tradeoff is to take advantage of knowing how the library code works to improve speed.
* Move nodes_of_class null check out of inner loopNick Drozd2018-03-021-1/+9
| | | | The check was being repeated unnecessarily in a tight loop.
* Add type-specific get_childrenNick Drozd2018-03-021-8/+222
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | get_children is elegant and flexible and slow. def get_children(self): for field in self._astroid_fields: attr = getattr(self, field) if attr is None: continue if isinstance(attr, (list, tuple)): for elt in attr: yield elt else: yield attr It iterates over a list, dynamically accesses attributes, does null checks, and does type checking. This function gets called a lot, and all that extra work is a real drag on performance. In most cases there isn't any need to do any of these checks. Take an Assign node for instance: def get_children(self): for elt in self.targets: yield elt yield self.value It's known in advance that Assign nodes have a list of targets and a value, so just yield those without checking anything.
* Fix lint errorsBryce Guinta2018-02-261-2/+2
|
* Remove Python 2 branches, assume we always run on Python 3Claudiu Popa2018-02-211-89/+47
|
* Make Unknown a rhs assignable nodeClaudiu Popa2017-12-151-1/+1
| | | | This means we can put an Unknown node in RHS of an assignment operations, which will be useful for brain related transforms.
* Public facing node documentationAshley Whetter2017-11-051-148/+2331
|
* Fix lint warningsClaudiu Popa2017-10-121-2/+4
|
* Arguments node gained a new attribute, kwonlyargs_annotations, for holding ↵Claudiu Popa2017-04-121-3/+12
| | | | the keyword-only args annotations
* Add support for asynchronous comprehensions (#400)Łukasz Rogalski2017-03-011-1/+4
| | | Closes #399
* Add support for Python 3.6's annotated assignment nodesrr-2017-02-091-0/+17
|
* Make is_argument search kwonlyargs. (#386)Derek Gustafson2017-01-221-1/+2
|
* Raise AstroidTypeError whenever a slice cannot be inferred, instead of ↵Claudiu Popa2016-12-181-1/+4
| | | | raising TypeError and letting the upper context to handle it.
* Remove occurrences of no-else-return and consider-using-ternaryClaudiu Popa2016-12-181-11/+7
|
* Reraise the exceptions as astroid exceptions in .getitem.Claudiu Popa2016-12-031-5/+9
|
* Let the type error propagate as an AstroidTypeError.Claudiu Popa2016-12-031-24/+40
|
* Remove pylint errorsDerek Gustafson2016-12-031-9/+8
|
* getitem() method accepts nodes now, instead of Python objects.Claudiu Popa2016-11-211-12/+67
|
* add format string support (#365)Jared Garst2016-10-241-0/+22
| | | Format strings require support for two new nodes, FormattedValue, respectively JoinedStr.
* Even more granular copyrights (thanks to copyrite)Claudiu Popa2016-07-221-2/+6
|
* Keep a consistent copyright notice across the board.Claudiu Popa2016-07-191-0/+2
|
* Introduce a special attributes modelClaudiu Popa2016-06-031-0/+11
| | | | | | | | Through this model, astroid starts knowing special attributes of certain Python objects, such as functions, classes, super objects and so on. This was previously possible before, but now the lookup and the attributes themselves are separated into a new module, objectmodel.py, which describes, in a more comprehensive way, the data model of each object.
* Fix typosJakub Wilk2016-06-021-10/+10
|
* Convert all files to new license headerCeridwen2016-05-161-17/+3
|
* Propagate error information to @raise_if_nothing_inferred in unpack_infer()Ceridwen2016-01-151-2/+7
|
* Fix unpack_infer to fail if results are emptyDave Baum2016-01-151-0/+1
| | | | | This should prevent a StopIteration leaking when next is called over unpack_infer.
* Enforce strong updates per frames.Claudiu Popa2016-01-121-3/+0
| | | | | | | | | | | | When looking up a name in a scope, Scope.lookup will return only the values which will be reachable after execution, as seen in the following code: a = 1 a = 2 In this case it doesn't make sense to return two values, but only the last one.
* Fix pylint errors.Claudiu Popa2015-12-141-0/+1
|
* Cleanup pylint's warnings over astroid codebaseClaudiu Popa2015-12-141-12/+30
| | | | | | | | | | Some of the messages were disabled in pylintrc, since they're not very useful for our case. Other parameters, such as the number of arguments / statements / attributes etc were configured so that they won't be too restrictive for our codebase, since making the code to respect them right now requires too much development changes, which is not justified by the end result. Closes issue #284.