News for hackers. Stuff that matters.
Re:Altering Python attribute handling for modules by fluidcruft on Monday September 11, 2023 @11:26AM (#37468695)

    import mpmath.mp as mp
Doesn't work in this case because mp isn't a submodule of mpmath. You will get "ModuleNotFoundError: No module named 'mpmath.mp'"

The "from" is what dives into a module and takes something out. It's not just defining a syntactic macro. You would have to do something closer to this:

    import mpmath
    mp = mpmath.mp
    del mpmath
to replace what "from" does.
Re:Altering Python attribute handling for modules by PurpleRamen on Monday September 11, 2023 @11:41AM (#37468933)
That's an implementation-detail. Nothing prevents the import from diving automatically into the file. But doing so would open the door for name-shadowing, as with a package you could have a separate mp.py for import, or a definition of mp in __init__.py. And this would be another confusion for people, and a performance-problem maybe.