-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improve traceback.FrameSummary
#7210
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
Conversation
This comment has been minimized.
This comment has been minimized.
Arguably these are true positives: |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/debug/tbtools.py:378: error: Unsupported operand types for - ("None" and "int") [operator]
+ src/werkzeug/debug/tbtools.py:378: note: Left operand is of type "Optional[int]"
pyp (https://github.com/hauntsaninja/pyp)
+ pyp.py:641: error: Argument 1 to "code_for_line" has incompatible type "Optional[int]"; expected "int"
core (https://github.com/home-assistant/core)
+ homeassistant/util/async_.py:158: error: Item "None" of "Optional[str]" has no attribute "strip" [union-attr]
+ homeassistant/util/async_.py:164: error: Item "None" of "Optional[str]" has no attribute "strip" [union-attr]
+ homeassistant/helpers/frame.py:112: error: Item "None" of "Optional[str]" has no attribute "strip" [union-attr]
|
@AlexWaygood any idea under what circumstances lineno can be None? edit: I got misled by something, removed some noise |
In practice it looks like lineno's in traceback come from https://github.com/python/cpython/blob/b27195332e91e932501f16cf9877761b218a9c99/Lib/traceback.py#L329 which we have as an int Line 520 in e3d4bdc
|
https://github.com/python/cpython/blob/b27195332e91e932501f16cf9877761b218a9c99/Lib/traceback.py#L305 looks pretty reachable to me, but I'll confess I don't know what real-life code ends up with us getting there :) |
So should we be changing TracebackType.tb_lineno? |
I don't know. I'm not an exception-handling expert, and the language reference doesn't shed much light here. Feel free to revert the |
This might have something to do with #6769. Presumably traceback line numbers come from stack frames. |
__len__
method.lineno
can beNone
line
is a read-only property that can bestr
orNone
, not astr
attribute.__getitem__
with overloads.__init__
signature, new instance attributes).Source code here: https://github.com/python/cpython/blob/b27195332e91e932501f16cf9877761b218a9c99/Lib/traceback.py#L243