mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-44313: generate LOAD_ATTR/CALL_FUNCTION for top-level imported objects (GH-26677)
This commit is contained in:
parent
66c53b48e1
commit
1b28187a0e
9 changed files with 279 additions and 214 deletions
|
@ -4278,6 +4278,23 @@ check_index(struct compiler *c, expr_ty e, expr_ty s)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
is_import_originated(struct compiler *c, expr_ty e)
|
||||
{
|
||||
/* Check whether the global scope has an import named
|
||||
e, if it is a Name object. For not traversing all the
|
||||
scope stack every time this function is called, it will
|
||||
only check the global scope to determine whether something
|
||||
is imported or not. */
|
||||
|
||||
if (e->kind != Name_kind) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
long flags = _PyST_GetSymbol(c->c_st->st_top, e->v.Name.id);
|
||||
return flags & DEF_IMPORT;
|
||||
}
|
||||
|
||||
// Return 1 if the method call was optimized, -1 if not, and 0 on error.
|
||||
static int
|
||||
maybe_optimize_method_call(struct compiler *c, expr_ty e)
|
||||
|
@ -4291,6 +4308,12 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
|
|||
if (meth->kind != Attribute_kind || meth->v.Attribute.ctx != Load) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check that the base object is not something that is imported */
|
||||
if (is_import_originated(c, meth->v.Attribute.value)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check that there aren't too many arguments */
|
||||
argsl = asdl_seq_LEN(args);
|
||||
kwdsl = asdl_seq_LEN(kwds);
|
||||
|
|
344
Python/importlib_external.h
generated
344
Python/importlib_external.h
generated
File diff suppressed because it is too large
Load diff
|
@ -122,9 +122,9 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
2,125,2,124,2,160,3,124,1,161,1,125,1,124,1,115,
|
||||
22,116,4,100,2,124,1,100,3,141,2,130,1,116,5,114,
|
||||
30,124,1,160,6,116,5,116,7,161,2,125,1,103,0,125,
|
||||
3,9,0,9,0,116,8,160,9,124,1,161,1,125,4,110,
|
||||
3,9,0,9,0,116,8,106,9,124,1,131,1,125,4,110,
|
||||
36,35,0,4,0,116,10,116,11,102,2,121,147,1,0,1,
|
||||
0,1,0,116,8,160,12,124,1,161,1,92,2,125,5,125,
|
||||
0,1,0,116,8,106,12,124,1,131,1,92,2,125,5,125,
|
||||
6,124,5,124,1,107,2,114,66,116,4,100,5,124,1,100,
|
||||
3,141,2,130,1,124,5,125,1,124,3,160,13,124,6,161,
|
||||
1,1,0,89,0,110,15,37,0,124,4,106,14,100,6,64,
|
||||
|
@ -172,7 +172,7 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
105,112,105,109,112,111,114,116,101,114,46,95,95,105,110,105,
|
||||
116,95,95,78,99,3,0,0,0,0,0,0,0,0,0,0,
|
||||
0,4,0,0,0,3,0,0,0,115,90,0,0,0,116,0,
|
||||
160,1,100,1,116,2,161,2,1,0,116,3,124,0,124,1,
|
||||
106,1,100,1,116,2,131,2,1,0,116,3,124,0,124,1,
|
||||
131,2,125,3,124,3,100,2,117,1,114,19,124,0,103,0,
|
||||
102,2,83,0,116,4,124,0,124,1,131,2,125,4,116,5,
|
||||
124,0,124,4,131,2,114,41,100,2,124,0,106,6,155,0,
|
||||
|
@ -234,8 +234,8 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
2,114,10,0,0,0,122,23,122,105,112,105,109,112,111,114,
|
||||
116,101,114,46,102,105,110,100,95,108,111,97,100,101,114,99,
|
||||
3,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,
|
||||
3,0,0,0,115,28,0,0,0,116,0,160,1,100,1,116,
|
||||
2,161,2,1,0,124,0,160,3,124,1,124,2,161,2,100,
|
||||
3,0,0,0,115,28,0,0,0,116,0,106,1,100,1,116,
|
||||
2,131,2,1,0,124,0,160,3,124,1,124,2,161,2,100,
|
||||
2,25,0,83,0,41,4,97,203,1,0,0,102,105,110,100,
|
||||
95,109,111,100,117,108,101,40,102,117,108,108,110,97,109,101,
|
||||
44,32,112,97,116,104,61,78,111,110,101,41,32,45,62,32,
|
||||
|
@ -280,13 +280,13 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
11,2,2,4,254,16,3,114,10,0,0,0,122,23,122,105,
|
||||
112,105,109,112,111,114,116,101,114,46,102,105,110,100,95,109,
|
||||
111,100,117,108,101,99,3,0,0,0,0,0,0,0,0,0,
|
||||
0,0,6,0,0,0,3,0,0,0,115,108,0,0,0,116,
|
||||
0,0,5,0,0,0,3,0,0,0,115,108,0,0,0,116,
|
||||
0,124,0,124,1,131,2,125,3,124,3,100,1,117,1,114,
|
||||
17,116,1,160,2,124,1,124,0,124,3,100,2,166,3,83,
|
||||
17,116,1,106,2,124,1,124,0,124,3,100,2,141,3,83,
|
||||
0,116,3,124,0,124,1,131,2,125,4,116,4,124,0,124,
|
||||
4,131,2,114,52,124,0,106,5,155,0,116,6,155,0,124,
|
||||
4,155,0,157,3,125,5,116,1,160,7,124,1,100,1,100,
|
||||
3,100,4,166,3,125,6,124,6,106,8,160,9,124,5,161,
|
||||
4,155,0,157,3,125,5,116,1,106,7,124,1,100,1,100,
|
||||
3,100,4,141,3,125,6,124,6,106,8,160,9,124,5,161,
|
||||
1,1,0,124,6,83,0,100,1,83,0,41,5,122,107,67,
|
||||
114,101,97,116,101,32,97,32,77,111,100,117,108,101,83,112,
|
||||
101,99,32,102,111,114,32,116,104,101,32,115,112,101,99,105,
|
||||
|
@ -387,8 +387,8 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
0,3,0,0,0,115,128,0,0,0,116,0,124,0,124,1,
|
||||
131,2,125,2,124,2,100,1,117,0,114,18,116,1,100,2,
|
||||
124,1,155,2,157,2,124,1,100,3,141,2,130,1,116,2,
|
||||
124,0,124,1,131,2,125,3,124,2,114,32,116,3,160,4,
|
||||
124,3,100,4,161,2,125,4,110,5,124,3,155,0,100,5,
|
||||
124,0,124,1,131,2,125,3,124,2,114,32,116,3,106,4,
|
||||
124,3,100,4,131,2,125,4,110,5,124,3,155,0,100,5,
|
||||
157,2,125,4,9,0,124,0,106,5,124,4,25,0,125,5,
|
||||
110,11,35,0,4,0,116,6,121,63,1,0,1,0,1,0,
|
||||
89,0,100,1,83,0,37,0,116,7,124,0,106,8,124,5,
|
||||
|
@ -447,22 +447,22 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
0,0,122,22,122,105,112,105,109,112,111,114,116,101,114,46,
|
||||
105,115,95,112,97,99,107,97,103,101,99,2,0,0,0,0,
|
||||
0,0,0,0,0,0,0,8,0,0,0,3,0,0,0,115,
|
||||
0,1,0,0,100,1,125,2,116,0,160,1,124,2,116,2,
|
||||
161,2,1,0,116,3,124,0,124,1,131,2,92,3,125,3,
|
||||
0,1,0,0,100,1,125,2,116,0,106,1,124,2,116,2,
|
||||
131,2,1,0,116,3,124,0,124,1,131,2,92,3,125,3,
|
||||
125,4,125,5,116,4,106,5,160,6,124,1,161,1,125,6,
|
||||
124,6,100,2,117,0,115,31,116,7,124,6,116,8,131,2,
|
||||
115,40,116,8,124,1,131,1,125,6,124,6,116,4,106,5,
|
||||
124,1,60,0,124,0,124,6,95,9,9,0,124,4,114,62,
|
||||
116,10,124,0,124,1,131,2,125,7,116,11,160,12,124,0,
|
||||
106,13,124,7,161,2,125,8,124,8,103,1,124,6,95,14,
|
||||
116,10,124,0,124,1,131,2,125,7,116,11,106,12,124,0,
|
||||
106,13,124,7,131,2,125,8,124,8,103,1,124,6,95,14,
|
||||
116,15,124,6,100,3,131,2,115,70,116,16,124,6,95,16,
|
||||
116,11,160,17,124,6,106,18,124,1,124,5,161,3,1,0,
|
||||
116,11,106,17,124,6,106,18,124,1,124,5,131,3,1,0,
|
||||
116,19,124,3,124,6,106,18,131,2,1,0,110,10,35,0,
|
||||
1,0,1,0,1,0,116,4,106,5,124,1,61,0,130,0,
|
||||
37,0,9,0,116,4,106,5,124,1,25,0,125,6,110,16,
|
||||
35,0,4,0,116,20,121,127,1,0,1,0,1,0,116,21,
|
||||
100,4,124,1,155,2,100,5,157,3,131,1,130,1,37,0,
|
||||
116,22,160,23,100,6,124,1,124,5,161,3,1,0,124,6,
|
||||
116,22,106,23,100,6,124,1,124,5,131,3,1,0,124,6,
|
||||
83,0,119,0,41,7,97,64,1,0,0,108,111,97,100,95,
|
||||
109,111,100,117,108,101,40,102,117,108,108,110,97,109,101,41,
|
||||
32,45,62,32,109,111,100,117,108,101,46,10,10,32,32,32,
|
||||
|
@ -623,7 +623,7 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
0,10,1,14,1,8,1,10,1,8,1,2,255,4,2,114,
|
||||
10,0,0,0,114,39,0,0,0,99,1,0,0,0,0,0,
|
||||
0,0,0,0,0,0,9,0,0,0,3,0,0,0,115,248,
|
||||
4,0,0,9,0,116,0,160,1,124,0,161,1,125,1,110,
|
||||
4,0,0,9,0,116,0,106,1,124,0,131,1,125,1,110,
|
||||
18,35,0,4,0,116,2,144,2,121,123,1,0,1,0,1,
|
||||
0,116,3,100,1,124,0,155,2,157,2,124,0,100,2,141,
|
||||
2,130,1,37,0,124,1,53,0,1,0,9,0,124,1,160,
|
||||
|
@ -695,13 +695,13 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
0,116,17,144,2,121,116,1,0,1,0,1,0,124,23,160,
|
||||
16,100,31,161,1,160,18,116,19,161,1,125,23,89,0,110,
|
||||
1,37,0,124,23,160,20,100,32,116,21,161,2,125,23,116,
|
||||
22,160,23,124,0,124,23,161,2,125,24,124,24,124,14,124,
|
||||
22,106,23,124,0,124,23,131,2,125,24,124,24,124,14,124,
|
||||
18,124,4,124,22,124,15,124,16,124,17,102,8,125,25,124,
|
||||
25,124,11,124,23,60,0,124,12,100,33,55,0,125,12,144,
|
||||
1,113,42,9,0,100,0,4,0,4,0,131,3,1,0,110,
|
||||
12,35,0,49,0,144,2,115,101,119,4,37,0,1,0,1,
|
||||
0,1,0,89,0,1,0,1,0,116,24,160,25,100,34,124,
|
||||
12,124,0,161,3,1,0,124,11,83,0,119,0,119,0,119,
|
||||
0,1,0,89,0,1,0,1,0,116,24,106,25,100,34,124,
|
||||
12,124,0,131,3,1,0,124,11,83,0,119,0,119,0,119,
|
||||
0,119,0,119,0,119,0,119,0,119,0,41,35,78,122,21,
|
||||
99,97,110,39,116,32,111,112,101,110,32,90,105,112,32,102,
|
||||
105,108,101,58,32,114,13,0,0,0,114,94,0,0,0,250,
|
||||
|
@ -822,13 +822,13 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
194,176,226,136,153,194,183,226,136,154,226,129,191,194,178,226,
|
||||
150,160,194,160,99,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,8,0,0,0,3,0,0,0,115,110,0,0,0,116,0,
|
||||
114,11,116,1,160,2,100,1,161,1,1,0,116,3,100,2,
|
||||
114,11,116,1,106,2,100,1,131,1,1,0,116,3,100,2,
|
||||
131,1,130,1,100,3,97,0,9,0,100,4,100,5,108,4,
|
||||
109,5,125,0,1,0,110,17,35,0,4,0,116,6,121,54,
|
||||
1,0,1,0,1,0,116,1,160,2,100,1,161,1,1,0,
|
||||
1,0,1,0,1,0,116,1,106,2,100,1,131,1,1,0,
|
||||
116,3,100,2,131,1,130,1,37,0,9,0,100,6,97,0,
|
||||
110,5,35,0,100,6,97,0,119,0,37,0,116,1,160,2,
|
||||
100,7,161,1,1,0,124,0,83,0,119,0,41,8,78,122,
|
||||
110,5,35,0,100,6,97,0,119,0,37,0,116,1,106,2,
|
||||
100,7,131,1,1,0,124,0,83,0,119,0,41,8,78,122,
|
||||
27,122,105,112,105,109,112,111,114,116,58,32,122,108,105,98,
|
||||
32,85,78,65,86,65,73,76,65,66,76,69,250,41,99,97,
|
||||
110,39,116,32,100,101,99,111,109,112,114,101,115,115,32,100,
|
||||
|
@ -851,7 +851,7 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
0,9,0,0,0,3,0,0,0,115,132,1,0,0,124,1,
|
||||
92,8,125,2,125,3,125,4,125,5,125,6,125,7,125,8,
|
||||
125,9,124,4,100,1,107,0,114,18,116,0,100,2,131,1,
|
||||
130,1,116,1,160,2,124,0,161,1,53,0,125,10,9,0,
|
||||
130,1,116,1,106,2,124,0,131,1,53,0,125,10,9,0,
|
||||
124,10,160,3,124,6,161,1,1,0,110,17,35,0,4,0,
|
||||
116,4,121,193,1,0,1,0,1,0,116,0,100,3,124,0,
|
||||
155,2,157,2,124,0,100,4,141,2,130,1,37,0,124,10,
|
||||
|
@ -913,21 +913,21 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
114,11,0,0,0,218,9,95,101,113,95,109,116,105,109,101,
|
||||
115,2,0,0,115,2,0,0,0,16,2,114,10,0,0,0,
|
||||
114,154,0,0,0,99,5,0,0,0,0,0,0,0,0,0,
|
||||
0,0,6,0,0,0,3,0,0,0,115,254,0,0,0,124,
|
||||
3,124,2,100,1,156,2,125,5,116,0,160,1,124,4,124,
|
||||
3,124,5,161,3,125,6,124,6,100,2,64,0,100,3,107,
|
||||
0,0,5,0,0,0,3,0,0,0,115,254,0,0,0,124,
|
||||
3,124,2,100,1,156,2,125,5,116,0,106,1,124,4,124,
|
||||
3,124,5,131,3,125,6,124,6,100,2,64,0,100,3,107,
|
||||
3,125,7,124,7,114,63,124,6,100,4,64,0,100,3,107,
|
||||
3,125,8,116,2,106,3,100,5,107,3,114,62,124,8,115,
|
||||
38,116,2,106,3,100,6,107,2,114,62,116,4,124,0,124,
|
||||
2,131,2,125,9,124,9,100,0,117,1,114,62,116,2,160,
|
||||
5,116,0,106,6,124,9,161,2,125,10,116,0,160,7,124,
|
||||
4,124,10,124,3,124,5,161,4,1,0,110,40,116,8,124,
|
||||
2,131,2,125,9,124,9,100,0,117,1,114,62,116,2,106,
|
||||
5,116,0,106,6,124,9,131,2,125,10,116,0,106,7,124,
|
||||
4,124,10,124,3,124,5,131,4,1,0,110,40,116,8,124,
|
||||
0,124,2,131,2,92,2,125,11,125,12,124,11,114,103,116,
|
||||
9,116,10,124,4,100,7,100,8,133,2,25,0,131,1,124,
|
||||
11,131,2,114,93,116,10,124,4,100,8,100,9,133,2,25,
|
||||
0,131,1,124,12,107,3,114,103,116,11,160,12,100,10,124,
|
||||
3,155,2,157,2,161,1,1,0,100,0,83,0,116,13,160,
|
||||
14,124,4,100,9,100,0,133,2,25,0,161,1,125,13,116,
|
||||
0,131,1,124,12,107,3,114,103,116,11,106,12,100,10,124,
|
||||
3,155,2,157,2,131,1,1,0,100,0,83,0,116,13,106,
|
||||
14,124,4,100,9,100,0,133,2,25,0,131,1,125,13,116,
|
||||
15,124,13,116,16,131,2,115,125,116,17,100,11,124,1,155,
|
||||
2,100,12,157,3,131,1,130,1,124,13,83,0,41,13,78,
|
||||
41,2,114,48,0,0,0,114,14,0,0,0,114,5,0,0,
|
||||
|
@ -987,11 +987,11 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
111,109,112,105,108,101,95,115,111,117,114,99,101,175,2,0,
|
||||
0,115,4,0,0,0,8,1,16,1,114,10,0,0,0,114,
|
||||
168,0,0,0,99,2,0,0,0,0,0,0,0,0,0,0,
|
||||
0,11,0,0,0,3,0,0,0,115,68,0,0,0,116,0,
|
||||
160,1,124,0,100,1,63,0,100,2,23,0,124,0,100,3,
|
||||
0,10,0,0,0,3,0,0,0,115,68,0,0,0,116,0,
|
||||
106,1,124,0,100,1,63,0,100,2,23,0,124,0,100,3,
|
||||
63,0,100,4,64,0,124,0,100,5,64,0,124,1,100,6,
|
||||
63,0,124,1,100,3,63,0,100,7,64,0,124,1,100,5,
|
||||
64,0,100,8,20,0,100,9,100,9,100,9,102,9,161,1,
|
||||
64,0,100,8,20,0,100,9,100,9,100,9,102,9,131,1,
|
||||
83,0,41,10,78,233,9,0,0,0,105,188,7,0,0,233,
|
||||
5,0,0,0,233,15,0,0,0,233,31,0,0,0,233,11,
|
||||
0,0,0,233,63,0,0,0,114,94,0,0,0,114,15,0,
|
||||
|
@ -1040,8 +1040,8 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
0,9,0,0,0,3,0,0,0,115,14,1,0,0,116,0,
|
||||
124,0,124,1,131,2,125,2,100,0,125,3,116,1,68,0,
|
||||
93,100,92,3,125,4,125,5,125,6,124,2,124,4,23,0,
|
||||
125,7,116,2,160,3,100,1,124,0,106,4,116,5,124,7,
|
||||
100,2,100,3,166,5,1,0,9,0,124,0,106,6,124,7,
|
||||
125,7,116,2,106,3,100,1,124,0,106,4,116,5,124,7,
|
||||
100,2,100,3,141,5,1,0,9,0,124,0,106,6,124,7,
|
||||
25,0,125,8,110,10,35,0,4,0,116,7,121,134,1,0,
|
||||
1,0,1,0,89,0,113,9,37,0,124,8,100,4,25,0,
|
||||
125,9,116,8,124,0,106,4,124,8,131,2,125,10,100,0,
|
||||
|
|
|
@ -391,7 +391,7 @@ PySymtable_Lookup(struct symtable *st, void *key)
|
|||
return (PySTEntryObject *)v;
|
||||
}
|
||||
|
||||
static long
|
||||
long
|
||||
_PyST_GetSymbol(PySTEntryObject *ste, PyObject *name)
|
||||
{
|
||||
PyObject *v = PyDict_GetItemWithError(ste->ste_symbols, name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue