diff --git a/jedi/api/refactoring.py b/jedi/api/refactoring.py index 5fd4c382..52943d9b 100644 --- a/jedi/api/refactoring.py +++ b/jedi/api/refactoring.py @@ -14,7 +14,7 @@ _INLINE_NEEDS_BRACKET = ( ).split() _EXTRACT_USE_PARENT = _INLINE_NEEDS_BRACKET + ['trailer'] _DEFINITION_SCOPES = ('suite', 'file_input') -_NON_EXCTRACABLE = ('param', 'keyword') +_NON_EXCTRACABLE = ('param',) class ChangedFile(object): @@ -242,7 +242,8 @@ def extract_variable(grammar, path, module_node, new_name, pos, until_pos): raise RefactoringError('Cannot extract anything from that') if any(node.type == 'name' and node.is_definition() for node in nodes): raise RefactoringError('Cannot extract a definition of a name') - if any(node.type in _NON_EXCTRACABLE for node in nodes): + if any(node.type in _NON_EXCTRACABLE for node in nodes) \ + or nodes[0].type == 'keyword' and nodes[0].value not in ('None', 'True', 'False'): raise RefactoringError('Cannot extract a %s' % node.type) definition = _get_parent_definition(node) diff --git a/test/refactor/extract_variable.py b/test/refactor/extract_variable.py index b9848a47..ecc6a54e 100644 --- a/test/refactor/extract_variable.py +++ b/test/refactor/extract_variable.py @@ -103,3 +103,12 @@ Cannot extract a keyword continue # ++++++++++++++++++++++++++++++++++++++++++++++++++ Cannot extract a keyword +# -------------------------------------------------- keyword-None +if 1: + #? 4 text {'new_name': 'x'} + None +# ++++++++++++++++++++++++++++++++++++++++++++++++++ +if 1: + #? 4 text {'new_name': 'x'} + x = None + x