[issue44313] Generate LOAD_ATTR+CALL_FUNCTION instead of LOAD_METHOD+CALL_METHOD for imports

Mark Shannon report at bugs.python.org
Thu Jun 10 04:37:15 EDT 2021


Mark Shannon <mark at hotpy.org> added the comment:

Yes. Simpler is good.


I think it will also be better for performance:

In general, we don't know what X is in `from Y import X`. It could be a module or anything else.

However, if we are accessing an attribute it is quite likely to be a module or class.
For `X` defined by `from Y import X`, `X` is likely to be a module, class, function, or some sort of constant like a string, int or Enum.

If it is a string, int or function then it is rare to call a method on it, so we can ignore that case.
Calling methods on an Enum constant is probably not very common either (I'm guessing here)

For a module, `LOAD_ATTR; CALL_FUNCTION` is clearly better than `LOAD_METHOD; CALL_METHOD`.

For a class, specializing `LOAD_ATTR` is no more complex than `LOAD_METHOD`, probably simpler.
So, for a class `LOAD_ATTR; CALL_FUNCTION` is no worse than `LOAD_METHOD; CALL_METHOD`, and might be better.


Overall, it looks like `X.foo()` when `X` is defiend by `from Y import X` is best as `LOAD_ATTR; CALL_FUNCTION` not `LOAD_METHOD; CALL_METHOD`.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44313>
_______________________________________


More information about the Python-bugs-list mailing list