Skip to content
Snippets Groups Projects
  1. Mar 16, 2018
  2. Mar 11, 2018
  3. Mar 10, 2018
  4. Mar 06, 2018
  5. Mar 05, 2018
  6. Mar 03, 2018
  7. Mar 02, 2018
    • Nick Drozd's avatar
      Add type-specific nodes_of_class · 9b5aa979
      Nick Drozd authored
      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.
      9b5aa979
    • Nick Drozd's avatar
      Move nodes_of_class null check out of inner loop · f44fced2
      Nick Drozd authored
      The check was being repeated unnecessarily in a tight loop.
      f44fced2
    • Nick Drozd's avatar
      Add type-specific get_children · 52e67656
      Nick Drozd authored
      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.
      52e67656
    • Bryce Guinta's avatar
      Update mro method docstring with additional possible exceptions · 7ead5dd6
      Bryce Guinta authored
      Prevents users from having to dig through the call chain to figure out which possible
      exceptions are raised
      7ead5dd6
    • Bryce Guinta's avatar
      Add inference for the builtin 'isinstance' · e1511f4c
      Bryce Guinta authored
      Close #98
      e1511f4c
    • Bryce Guinta's avatar
    • Bryce Guinta's avatar
  8. Feb 27, 2018
  9. Feb 22, 2018
  10. Feb 21, 2018
  11. Feb 19, 2018
    • Bryce Guinta's avatar
      Fix augassign recursion error · 3fae32f9
      Bryce Guinta authored
      The augmented assign rhs context path was deleted most likely
      due to a recently fixed inference bug where InferenceContext path
      attributes were shared between objects.
      
      Recursive functions on the right hand side of the augmented assign would
      forget that they were already called, causing an eventual RecursionError
      in astroid inference
      
      Now that the InferenceContext clone() method properly copies the
      inference path between Contexts, it's fine to remove this hack.
      
      Fixes #437, Fixes #447, Fixes #313, Fixes PyCQA/pylint#1642, Fixes PyCQA/pylint#1805, Fixes PyCQA/pylint#1854, Fixes PyCQA/pylint#1452
      3fae32f9
  12. Feb 17, 2018
  13. Feb 16, 2018
  14. Feb 15, 2018
Loading