Skip to content

Commit

Permalink
fix(tests): Fix exception on copying frame.f_locals (Python 3.13)
Browse files Browse the repository at this point in the history
Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but
`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python
3.13 and later, it should be copied using a method `.copy()`. The new way
of copying works the same as the old one for versions of Python prior to
3.13, according to the documentation (both copying methods produce a
shallow copy).

See:
https://peps.python.org/pep-0667/
python/cpython#118921
python/cpython#118923
https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13
https://docs.python.org/3/library/copy.html
  • Loading branch information
rominf committed Jul 10, 2024
1 parent 4f5fe0a commit 5536c2a
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import threading
import time
from collections import namedtuple
from copy import copy
from datetime import datetime
from decimal import Decimal
from functools import partial, partialmethod, wraps
Expand Down Expand Up @@ -618,7 +617,7 @@ def serialize_frame(
)

if include_local_variables:
rv["vars"] = copy(frame.f_locals)
rv["vars"] = frame.f_locals.copy()

return rv

Expand Down

0 comments on commit 5536c2a

Please sign in to comment.