mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
gh-118465: Add __firstlineno__ attribute to class (GH-118475)
It is set by compiler with the line number of the first line of the class definition.
This commit is contained in:
parent
716ec4bfcf
commit
153b3f7530
17 changed files with 61 additions and 89 deletions
|
@ -2502,6 +2502,11 @@ compiler_class_body(struct compiler *c, stmt_ty s, int firstlineno)
|
|||
compiler_exit_scope(c);
|
||||
return ERROR;
|
||||
}
|
||||
ADDOP_LOAD_CONST_NEW(c, loc, PyLong_FromLong(c->u->u_metadata.u_firstlineno));
|
||||
if (compiler_nameop(c, loc, &_Py_ID(__firstlineno__), Store) < 0) {
|
||||
compiler_exit_scope(c);
|
||||
return ERROR;
|
||||
}
|
||||
asdl_type_param_seq *type_params = s->v.ClassDef.type_params;
|
||||
if (asdl_seq_LEN(type_params) > 0) {
|
||||
if (!compiler_set_type_params_in_class(c, loc)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue