Fix munging of __version__

This commit is contained in:
Jeff Epler 2024-01-11 09:06:01 -06:00
parent 1fa9182855
commit ce6de427be
No known key found for this signature in database
GPG key ID: D5BF15AB975AB4DE

View file

@ -99,7 +99,7 @@ def munge(src: pathlib.Path|str, version_str: str) -> str:
# return the statements in the else branch of 'if TYPE_CHECKING: ...'
elif ast.unparse(node.test) == 'TYPE_CHECKING':
replace(node.lineno, 'if 0:')
elif isinstance(node, ast.Assign) and node.targets[0].id == '__version__':
elif isinstance(node, ast.Assign) and isinstance(node.targets[0], ast.Name) and node.targets[0].id == '__version__':
replace(node.lineno, f"__version__ = \"{version_str}\"")
content = pathlib.Path(path).read_text(encoding="utf-8")