Skip to content

Renaming globals isn't aware of imports from local source files #126

@kevinjwalters

Description

@kevinjwalters

If you have multiple files with and import statements then --rename-globals cannot be used.

For the files program.py

from library1 import NUMBER
import library2
instance = library2.SomethingClass()
print(NUMBER)

and library1.py

A=1.234

and library2.py

class SomethingClass():
    def __init__(self):
        self.name = "something"

these arguments

pyminify --remove-literal-statements --rename-globals --in-place program.py library1.py library2.py

produce output that does not work.

from library1 import NUMBER as A
import library2 as B
C=B.SomethingClass()
print(A)
A=1.234
class A:
        def __init__(A):A._name='something'

One workaround here is to always import things with from and do a hacky, fragile grep of that to produce symbols to be excluded using --preserve-globals.

I'm using this on some MicroPython code to squeeze it into a small file system on the micro:bit and apart from this and maybe some issues with MicroPython's special const() it works really well, thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions