diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-05-06 09:02:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-06 09:02:37 (GMT) |
commit | 153b3f75306b5d26e29ea157105d0fdc247ef853 (patch) | |
tree | f73ede56af175d27698ef56bec21073f98889bbc /Python | |
parent | 716ec4bfcf1a564db9936122c442baa99f9c4a8c (diff) | |
download | cpython-153b3f75306b5d26e29ea157105d0fdc247ef853.zip cpython-153b3f75306b5d26e29ea157105d0fdc247ef853.tar.gz cpython-153b3f75306b5d26e29ea157105d0fdc247ef853.tar.bz2 |
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.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c index 35a7848..79f3baa 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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)) { |