Exemple #1
0
 def multi_line_conditions(self, info):
     node = _parse_text(info.source[info.region[0]:info.region[1]])
     count = usefunction._return_count(node)
     if count > 1:
         raise RefactoringError('Extracted piece can have only one '
                                'return statement.')
     if usefunction._yield_count(node):
         raise RefactoringError('Extracted piece cannot '
                                'have yield statements.')
     if count == 1 and not usefunction._returns_last(node):
         raise RefactoringError('Return should be the last statement.')
     if info.region != info.lines_region:
         raise RefactoringError('Extracted piece should '
                                'contain complete statements.')
Exemple #2
0
 def base_conditions(self, info):
     if info.region[1] > info.scope_region[1]:
         raise RefactoringError('Bad region selected for extract method')
     end_line = info.region_lines[1]
     end_scope = info.global_scope.get_inner_scope_for_line(end_line)
     if end_scope != info.scope and end_scope.get_end() != end_line:
         raise RefactoringError('Bad region selected for extract method')
     try:
         extracted = info.source[info.region[0]:info.region[1]]
         if info.one_line:
             extracted = '(%s)' % extracted
         if _UnmatchedBreakOrContinueFinder.has_errors(extracted):
             raise RefactoringError('A break/continue without having a '
                                    'matching for/while loop.')
     except SyntaxError:
         raise RefactoringError('Extracted piece should '
                                'contain complete statements.')
Exemple #3
0
 def _get_function_signature(self, args):
     args = list(args)
     prefix = ''
     if self._extracting_method():
         self_name = self._get_self_name()
         if self_name is None:
             raise RefactoringError('Extracting a method from a function '
                                    'with no self argument.')
         if self_name in args:
             args.remove(self_name)
         args.insert(0, self_name)
     return prefix + self.info.new_name + \
         '(%s)' % self._get_comma_form(args)
Exemple #4
0
 def one_line_conditions(self, info):
     if self._is_region_on_a_word(info):
         raise RefactoringError('Should extract complete statements.')
     if info.variable and not info.one_line:
         raise RefactoringError('Extract variable should not '
                                'span multiple lines.')