Skip to content

sys.settrace: frame.f_code.co_firstlineno is 1 above the correct value #16797

@rkompass

Description

@rkompass

Port, board and/or hardware

Pyboard, but probably doesn't matter

MicroPython version

MicroPython v1.25.0-preview.316.g5214d8a29.dirty on 2025-02-14; PYBv1.1 with STM32F405RG

Reproduction

import sys

def add1(x):
    return x+1

def foo(x):
    return add1(x)+add1(x)

def trace(frame, event, arg):
    bcode = []
    for b in frame.f_code.co_code:
        bcode.append(hex(b))
    if event == 'call':
        print(f'trace: {event} {frame.f_lineno}:{frame.f_code.co_name} <-from {frame.f_back.f_lineno}:{frame.f_back.f_code.co_name}')
        print(f'calling file "{frame.f_code.co_filename}" at line: {frame.f_code.co_firstlineno}')
    return

sys.settrace(trace)
foo(42)
sys.settrace(None)

Expected behaviour (CPython)

trace: call 6:foo <-from 20:<module>
calling file "/home/raul/Micropython/settrace_errdemo.py" at line: 6
trace: call 3:add1 <-from 7:foo
calling file "/home/raul/Micropython/settrace_errdemo.py" at line: 3
trace: call 3:add1 <-from 7:foo
calling file "/home/raul/Micropython/settrace_errdemo.py" at line: 3

Observed behaviour (Micropython)

trace: call 6:foo <-from 20:<module>
calling file "settrace_errdemo.py" at line: 7
trace: call 3:add1 <-from 7:foo
calling file "settrace_errdemo.py" at line: 4
trace: call 3:add1 <-from 7:foo
calling file "settrace_errdemo.py" at line: 4

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      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