diff options
author | Jimmy <jimmy@spalge.com> | 2022-04-15 14:49:49 +1200 |
---|---|---|
committer | Jimmy <jimmy@spalge.com> | 2022-04-30 13:34:31 +1200 |
commit | 557a8d4b66c7bc17927a706a8103392b87895494 (patch) | |
tree | ee988bf780457b9edc8713a4460cddf06d30423a | |
parent | 5f611c8b34ef8526fe0a7ced887d48f0f07c1d68 (diff) | |
download | qutebrowser-557a8d4b66c7bc17927a706a8103392b87895494.tar.gz qutebrowser-557a8d4b66c7bc17927a706a8103392b87895494.zip |
fix upstream bug 16e1c0679a25529
When the target rename was something like "a.b.c" and the file happened
to do a simple "import a" it would fail with `CSTValidationError:
Cannot have empty name identifier.` when trying to construct a new
import alias. Because the result of gen_replacement_module() in this
case was an empty string. Which is apparently used for "no replacement
required", which is accurate in this case.
This is a bandaid, the problem is more likely to be that the
`old_name.startswith(import_alias_full_name+'.')` conditional is too
simplistic.
-rw-r--r-- | scripts/codemods/rename_pyqt.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/scripts/codemods/rename_pyqt.py b/scripts/codemods/rename_pyqt.py index 306203c82..ba20f4f54 100644 --- a/scripts/codemods/rename_pyqt.py +++ b/scripts/codemods/rename_pyqt.py @@ -139,33 +139,31 @@ class RenameCommand(VisitorBasedCodemodCommand): if import_alias_full_name is None: raise Exception("Could not parse full name for ImportAlias.name node.") + replacement_module = self.gen_replacement_module(import_alias_full_name) if isinstance(import_alias_name, cst.Name) and self.old_name.startswith( import_alias_full_name + "." - ): + ) and replacement_module: # Might, be in use elsewhere in the code, so schedule a potential removal, and add another alias. new_names.append(import_alias) self.scheduled_removals.add(original_node) - print(f"leave_Import {import_alias_full_name=} -> {self.gen_replacement_module(import_alias_full_name)=} {self.old_name=} {import_alias=} {updated_node=} {import_alias=}") - replacement_name = self.gen_replacement_module(import_alias_full_name) + print(f"leave_Import down {original_node=} {import_alias_full_name=} -> {self.gen_replacement_module(import_alias_full_name)=} {self.old_name=} {import_alias=} {updated_node=} {import_alias=}") new_names.append( cst.ImportAlias( name=cst.Name( - value=replacement_name, + value=replacement_module, ) ) ) self.bypass_import = True elif isinstance( import_alias_name, cst.Attribute - ) and self.old_name.startswith(import_alias_full_name + "."): + ) and self.old_name.startswith(import_alias_full_name + ".") and replacement_module: # Same idea as above. new_names.append(import_alias) self.scheduled_removals.add(original_node) new_name_node: Union[ cst.Attribute, cst.Name - ] = self.gen_name_or_attr_node( - self.gen_replacement_module(import_alias_full_name) - ) + ] = self.gen_name_or_attr_node(replacement_module) new_names.append(cst.ImportAlias(name=new_name_node)) self.bypass_import = True else: |