Skip to content

py/objcode: Remove co_lnotab from v2 preview. #17639

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

Merged
merged 2 commits into from
Jul 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions py/objcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static mp_obj_tuple_t *code_consts(const mp_module_context_t *context, const mp_
return consts;
}

#if !MICROPY_PREVIEW_VERSION_2
static mp_obj_t raw_code_lnotab(const mp_raw_code_t *rc) {
// const mp_bytecode_prelude_t *prelude = &rc->prelude;
uint start = 0;
Expand Down Expand Up @@ -106,6 +107,7 @@ static mp_obj_t raw_code_lnotab(const mp_raw_code_t *rc) {
m_del(byte, buffer, buffer_size);
return o;
}
#endif

static mp_obj_t code_colines_iter(mp_obj_t);
static mp_obj_t code_colines_next(mp_obj_t);
Expand Down Expand Up @@ -198,12 +200,14 @@ static void code_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
case MP_QSTR_co_names:
dest[0] = MP_OBJ_FROM_PTR(o->dict_locals);
break;
#if !MICROPY_PREVIEW_VERSION_2
case MP_QSTR_co_lnotab:
if (!o->lnotab) {
o->lnotab = raw_code_lnotab(rc);
}
dest[0] = o->lnotab;
break;
#endif
case MP_QSTR_co_lines:
dest[0] = MP_OBJ_FROM_PTR(&code_colines_obj);
dest[1] = self_in;
Expand Down
7 changes: 0 additions & 7 deletions tests/basics/fun_code_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
print("SKIP")
raise SystemExit

try:
import warnings
warnings.simplefilter("ignore") # ignore deprecation warning about co_lnotab
except ImportError:
pass

def f(x, y):
a = x + y
b = x - y
Expand All @@ -25,7 +19,6 @@ def f(x, y):
print(type(code.co_firstlineno)) # both ints (but mpy points to first line inside, cpy points to declaration)
print(code.co_name)
print(iter(code.co_names) is not None) # both iterable (but mpy returns dict with names as keys, cpy only the names; and not necessarily the same set)
print(type(code.co_lnotab)) # both bytes

co_lines = code.co_lines()

Expand Down
34 changes: 34 additions & 0 deletions tests/basics/fun_code_lnotab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Test deprecation of co_lnotab

try:
(lambda: 0).__code__.co_code
except AttributeError:
print("SKIP")
raise SystemExit


import unittest
import sys


mpy_is_v2 = getattr(sys.implementation, '_v2', False)


def f():
pass


class Test(unittest.TestCase):

@unittest.skipIf(mpy_is_v2, "Removed in MicroPython v2 and later.")
def test_co_lnotab_exists(self):
self.assertIsInstance(f.__code__.co_lnotab, bytes)

@unittest.skipUnless(mpy_is_v2, "Not removed before MicroPython v2.")
def test_co_lnotab_removed(self):
with self.assertRaises(AttributeError):
f.__code__.co_lnotab


if __name__ == "__main__":
unittest.main()
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy