FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve `traceback.FrameSummary` by AlexWaygood · Pull Request #7210 · python/typeshed · GitHub

Repository navigation

Improve traceback.FrameSummary - #7210

Merged
JelleZijlstra merged 4 commits into
python:masterfrom
AlexWaygood:FrameSummary
Feb 15, 2022
Merged

JelleZijlstra merged 4 commits into
python:masterfrom
AlexWaygood:FrameSummary

Conversation

AlexWaygood commented Feb 14, 2022 •
edited
Loading

Copy link
Copy Markdown
Member
  • Add missing __len__ method.
  • lineno can be None
  • line is a read-only property that can be str or None, not a str attribute.
  • Improve __getitem__ with overloads.
  • Reflect changes to the class that have been made in 3.11 (new __init__ signature, new instance attributes).

Source code here: https://github.com/python/cpython/blob/b27195332e91e932501f16cf9877761b218a9c99/Lib/traceback.py#L243

This comment has been minimized.

Copy link
Copy Markdown
Member Author

Diff from mypy_primer, showing the effect of this PR on open source code:

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]

Arguably these are true positives: line can clearly be None

This comment has been minimized.

Copy link
Copy Markdown
Contributor

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]

hauntsaninja commented Jul 19, 2022 •
edited
Loading

Copy link
Copy Markdown
Collaborator

@AlexWaygood any idea under what circumstances lineno can be None?

edit: I got misled by something, removed some noise

hauntsaninja commented Jul 19, 2022 •
edited
Loading

Copy link
Copy Markdown
Collaborator

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

def tb_lineno(self) -> int: ...

Copy link
Copy Markdown
Member Author

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 :)

Copy link
Copy Markdown
Collaborator

So should we be changing TracebackType.tb_lineno?

Copy link
Copy Markdown
Member Author

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 int -> int | None changes if you're confident I'm incorrect here :)

Akuli commented Jul 19, 2022

Copy link
Copy Markdown
Collaborator

This might have something to do with #6769. Presumably traceback line numbers come from stack frames.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL