Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _check_exceptional_conditions(self):
if self.old_pyname is None or \
not isinstance(self.old_pyname.get_object(), pyobjects.PyDefinedObject):
raise exceptions.RefactoringError(
'Move refactoring should be performed on a class/function.')
moving_pyobject = self.old_pyname.get_object()
if not self._is_global(moving_pyobject):
raise exceptions.RefactoringError(
'Move refactoring should be performed on a global class/function.')
def _check_exceptional_conditions(self):
if self.old_pyname is None or \
not isinstance(self.old_pyname.get_object(), pyobjects.PyDefinedObject):
raise exceptions.RefactoringError(
'Move refactoring should be performed on a class/function.')
moving_pyobject = self.old_pyname.get_object()
if not self._is_global(moving_pyobject):
raise exceptions.RefactoringError(
'Move refactoring should be performed on a global class/function.')
def _check_nothing_after_return(self, source, offset):
lines = codeanalyze.SourceLinesAdapter(source)
lineno = lines.get_line_number(offset)
logical_lines = codeanalyze.LogicalLineFinder(lines)
lineno = logical_lines.logical_line_in(lineno)[1]
if source[lines.get_line_end(lineno):len(source)].strip() != '':
raise rope.base.exceptions.RefactoringError(
'Cannot inline functions with statements after return statement.')
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.')
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.')
def get_changes(self, dest, resources=None,
task_handle=taskhandle.NullTaskHandle()):
if resources is None:
resources = self.pycore.get_python_files()
if dest is None or not dest.exists():
raise exceptions.RefactoringError(
'Move destination does not exist.')
if dest.is_folder() and dest.has_child('__init__.py'):
dest = dest.get_child('__init__.py')
if dest.is_folder():
raise exceptions.RefactoringError(
'Move destination for non-modules should not be folders.')
if self.source == dest:
raise exceptions.RefactoringError(
'Moving global elements to the same module.')
return self._calculate_changes(dest, resources, task_handle)
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.')
def __init__(self, project, resource, offset):
self.project = project
self.resource = resource
self.offset = offset
self.pymodule = self.project.get_pymodule(self.resource)
scope = self.pymodule.get_scope().get_inner_scope_for_offset(offset)
if scope.get_kind() != 'Function':
raise exceptions.RefactoringError(
'Introduce parameter should be performed inside functions')
self.pyfunction = scope.pyobject
self.name, self.pyname = self._get_name_and_pyname()
if self.pyname is None:
raise exceptions.RefactoringError(
'Cannot find the definition of <%s>' % self.name)
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.')