bwesterb / py-demandimport

Lazy import python modules for low start-up time. (Taken from mercurial.)
GNU General Public License v2.0
48 stars 8 forks source link

import matplotlib.pyplot as plt doesn't work with demandimport.enabled() #11

Open Asmageddon opened 1 year ago

Asmageddon commented 1 year ago

I tried all of the following forms:

with demandimport.enabled():
    # Doesn't work at all
    import matplotlib.pyplot as plt
    from matplotlib import pyplot as plt
    from matplotlib import pyplot
    # Works but can't be reassigned to `plt`.
    import matplotlib.pyplot
    plt = matplotlib.pyplot # Throws a huge error
    plt = object.__getattribute__(matplotlib, "pyplot") # '_demandmod' object has no attribute 'pyplot'

The only form that actually worked was:

with demandimport.enabled():
    import matplotlib.pyplot
plt = matplotlib.pyplot

type(plt) # demandimport._demandmod