Skip to content
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

fail-on-template-vars: modernize stack inspection code #1129

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

xavfernandez
Copy link
Contributor

inspect.stack() returns a list of namedtuple (or retrocompatible objects) since Python 3.5+: let's use the named attribute.

cf https://docs.python.org/3/library/inspect.html#inspect.stack

And once we have access to a FrameInfo object/namedtuple, access to its frame object and its f_locals member should not need to iterate on all its members:
https://docs.python.org/3/reference/datamodel.html#frame-objects

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup, thanks!

pytest_django/plugin.py Outdated Show resolved Hide resolved
xavfernandez and others added 2 commits September 2, 2024 14:16
inspect.stack() returns a list of namedtuple (or retrocompatible
objects) since Python 3.5+: let's use the named attribute.

cf https://docs.python.org/3/library/inspect.html#inspect.stack

And once we have access to a FrameInfo object/namedtuple, access to its
frame object and its f_locals member should not need to iterate on all
its members:
https://docs.python.org/3/reference/datamodel.html#frame-objects
@bluetech bluetech merged commit 19605d7 into pytest-dev:main Sep 2, 2024
16 of 17 checks passed
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.

2 participants