hpython
hpython copied to clipboard
Following imports
Eventually I want to be able to parse and validate imported modules. Not going to do it yet, but I'm going to do some brainstorming here.
https://docs.python.org/3.5/reference/import.html#searching
- We'll have to duplicate the "finders and loaders" logic
- Should probably make import awareness work for calls to
importlib.import_module
as well as import statements - Need to warn about importing inside control flow, as we can't give useful guarantees
I was just thinking about this today. I'd love it if hpython
could do some tree-shaking ala webpack. The problem, in python as well as in javascript is that importing modules is not declarative (and can have side effects too!).
Eg. in Python is common to do the following
if FLAG:
import moduleA
else:
import moduleB
where FLAG
can well be something computed at runtime.
As common as above is this
try:
import moduleA
except:
import moduleB
Yep that's the 3rd bullet point :) I've come up against similar issues in scope checking. I wish it wasn't this way.
Yep that's the 3rd bullet point :)
😊
I've come up against similar issues in scope checking. I wish it wasn't this way.
Reading https://docs.python.org/3.5/library/functions.html#__import__
is a big depressing.
This function is invoked by the import statement. It can be replaced (by importing the builtins module and assigning to builtins.import) in order to change semantics of the import statement, but doing so is strongly discouraged as it is usually simpler to use import hooks (see PEP 302) to attain the same goals and does not cause issues with code which assumes the default import implementation is in use. Direct use of import() is also discouraged in favor of importlib.import_module().
I wonder what guarantees can be given about Python at all.
I wonder what guarantees can be given about Python at all.
The +
function does not format your disk.
maybe, hopefully
>>> int.__add__ = better_add
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't set attributes of built-in/extension type 'int'
At this point I am not sure if I should be happy or sad ...
Definitely happy, because I've tried that same thing before :P