cknd / stackprinter

Debugging-friendly exceptions for Python
MIT License
1.28k stars 37 forks source link

Can't accept non-string multiline tokens #68

Closed ale-dd closed 7 months ago

ale-dd commented 8 months ago

Recently, quite often I end up struggling with this error:


  File "venv312/lib/python3.12/site-packages/stackprinter/source_inspection.py", line 151, in _tokenize
    assert sline == eline, "Can't accept non-string multiline tokens"
AssertionError: Can't accept non-string multiline tokens```

Any hint as to what may be going on?
cknd commented 8 months ago

Hey! could you paste some of the source code context on which stackprinter gives this error?

ale-dd commented 8 months ago

It happens in so many places I don't think it's a "local" problem. I wonder if it might have to do with the order of imports and with the use of asyncio + threadpools + nest_asyncio + uvloop?

cknd commented 8 months ago

can you give me access to a piece of code on which I can reproduce the problem?

cknd commented 8 months ago

(I can't guess the underlying bug, I need to see it fail and then look at the error traces and step through with a debugger)

cknd commented 7 months ago

update: we were able to isolate this to multi-line f-strings on python >= 3.12 (works on python < 3.12)

# fails on py 3.12:

try:
    thing = 42
    f"""bla
        blub
        {thing}
        bla
        """
    raise Exception()
except:
    stackprinter.show()

investigating

cknd commented 7 months ago

This was surprisingly simple in the end -- it should work now with version 0.2.12