-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-119180: PEP 649 compiler changes #119361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
985f8df
c822ffa
e80095e
90ff2c4
026c0ff
7968744
4e54197
4469b32
47d672e
ab9359c
e65d55a
e50cd62
afae5c0
e5a7b1a
3f26d44
31a4471
fbb1d88
f452eb2
8c4b4e3
cbf9a3d
5d182fc
ce98c19
e0578fc
ed16167
f38de20
87baca2
355d3df
f9d81b6
dd1f64a
62f5b3b
b66ad8b
1a63f5d
82c0dbc
a0c39b5
083bbc5
de1b235
1c98fe5
5f5cf11
77f3b1c
4217830
13f5d76
a121e1a
242301c
239ba23
b62e04c
c8a9294
5ae206d
24fd328
0f9d0c5
c181864
0befff5
ada6573
ae7714c
431811a
7ca24d3
2ab5d07
3b4a645
1dfd02b
daba318
0daf0b1
b066b3d
7669361
c6a1b80
5cdbdd7
e748feb
a2b4f9e
bd469ab
278de22
487ea34
8f486ba
6b563db
0058b82
517fb56
21f93b6
f72dbca
8674eab
ee11fd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,11 @@ class A(builtins.object) | |
| __weakref__%s | ||
|
||
class B(builtins.object) | ||
| Methods defined here: | ||
| | ||
| __annotate__(...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (It would be great if we could generate a nice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're actually Python function, so I wonder why pydoc doesn't pick them up. Possibly because the parameter is called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed:
Maybe in a followup PR we can figure out a way to make this work. The parameter has to have an illegal name so it doesn't shadow any symbol name that the user might have used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure I 100% understand this point, and no tests seem to fail if I make this change locally to your PR branch and recompile (and I verified that it means that diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h
index 009802c4416..899b19ae941 100644
--- a/Include/internal/pycore_global_strings.h
+++ b/Include/internal/pycore_global_strings.h
@@ -45,7 +45,7 @@ struct _Py_global_strings {
STRUCT_FOR_STR(dot, ".")
STRUCT_FOR_STR(dot_locals, ".<locals>")
STRUCT_FOR_STR(empty, "")
- STRUCT_FOR_STR(format, ".format")
+ STRUCT_FOR_STR(format, "format")
STRUCT_FOR_STR(generic_base, ".generic_base")
STRUCT_FOR_STR(json_decoder, "json.decoder")
STRUCT_FOR_STR(kwdefaults, ".kwdefaults")
diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h
index ff5b6ee8e0f..e8b5173a457 100644
--- a/Include/internal/pycore_runtime_init_generated.h
+++ b/Include/internal/pycore_runtime_init_generated.h
@@ -554,7 +554,7 @@ extern "C" {
INIT_STR(dot, "."), \
INIT_STR(dot_locals, ".<locals>"), \
INIT_STR(empty, ""), \
- INIT_STR(format, ".format"), \
+ INIT_STR(format, "format"), \
INIT_STR(generic_base, ".generic_base"), \
INIT_STR(json_decoder, "json.decoder"), \
INIT_STR(kwdefaults, ".kwdefaults"), \
diff --git a/Python/compile.c b/Python/compile.c
index c3372766d0b..7535067ded0 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1447,7 +1447,7 @@ compiler_setup_annotations_scope(struct compiler *c, location loc,
}
c->u->u_metadata.u_posonlyargcount = 1;
// if .format != 1: raise NotImplementedError
- _Py_DECLARE_STR(format, ".format");
+ _Py_DECLARE_STR(format, "format");
ADDOP_I(c, loc, LOAD_FAST, 0);
ADDOP_LOAD_CONST(c, loc, _PyLong_GetOne());
ADDOP_I(c, loc, COMPARE_OP, (Py_NE << 5) | compare_masks[Py_NE]);
diff --git a/Python/symtable.c b/Python/symtable.c
index 23fc4a0ec03..0154092a905 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -2511,7 +2511,7 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
}
}
- _Py_DECLARE_STR(format, ".format");
+ _Py_DECLARE_STR(format, "format");
// The generated __annotate__ function takes a single parameter with the
// internal name ".format".
if (!symtable_add_def(st, &_Py_STR(format), DEF_PARAM,
@@ -2570,7 +2570,7 @@ symtable_visit_annotations(struct symtable *st, stmt_ty o, arguments_ty a, expr_
return 0;
}
}
- _Py_DECLARE_STR(format, ".format");
+ _Py_DECLARE_STR(format, "format");
// We need to insert code that reads this "parameter" to the function.
if (!symtable_add_def(st, &_Py_STR(format), DEF_PARAM, LOCATION(o))) {
return 0; This also might be worth a brief mention in PEP-749, since PEP-649 seems to specify that the signature of In any event, this can definitely be tackled in a followup; I don't want to block this PR! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try something like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, makes sense! Worth adding a test like that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, the problem is that any such test can only tell us about one specific name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, it doesn't verify any fundamental invariants about Thanks for adding it! |
||
| | ||
| ---------------------------------------------------------------------- | ||
| Data descriptors defined here: | ||
| | ||
| __dict__%s | ||
|
@@ -87,8 +92,6 @@ class B(builtins.object) | |
| Data and other attributes defined here: | ||
| | ||
| NO_MEANING = 'eggs' | ||
| | ||
| __annotations__ = {'NO_MEANING': <class 'str'>} | ||
|
||
class C(builtins.object) | ||
| Methods defined here: | ||
|
@@ -176,6 +179,9 @@ class A(builtins.object) | |
list of weak references to the object | ||
|
||
class B(builtins.object) | ||
Methods defined here: | ||
__annotate__(...) | ||
---------------------------------------------------------------------- | ||
Data descriptors defined here: | ||
__dict__ | ||
dictionary for instance variables | ||
|
@@ -184,7 +190,6 @@ class B(builtins.object) | |
---------------------------------------------------------------------- | ||
Data and other attributes defined here: | ||
NO_MEANING = 'eggs' | ||
__annotations__ = {'NO_MEANING': <class 'str'>} | ||
|
||
|
||
class C(builtins.object) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ def test_runsource_shows_syntax_error_for_failed_compilation(self): | |
|
||
def test_no_active_future(self): | ||
console = InteractiveColoredConsole() | ||
source = "x: int = 1; print(__annotations__)" | ||
source = "x: int = 1; print(__annotate__(1))" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does printing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Printing a global doesn't go through the descriptor protocol, so printing |
||
f = io.StringIO() | ||
with contextlib.redirect_stdout(f): | ||
result = console.runsource(source) | ||
|
Uh oh!
There was an error while loading. Please reload this page.