Skip to content

Commit

Permalink
- Adjust for incompatible changes in Python 3.13b1
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed May 13, 2024
1 parent 998214b commit adab2bd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
6.4 (unreleased)
================

- Adjust for incompatible changes in Python 3.13b1.
(`#292 <https://github.com/zopefoundation/zope.interface/issues/292>`)

- Build windows wheels on GHA.

6.3 (2024-04-12)
Expand Down
3 changes: 3 additions & 0 deletions src/zope/interface/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def _normalize_name(name):
return name
raise TypeError("name must be a string or ASCII-only bytes")


PYPY = hasattr(sys, 'pypy_version_info')
_version = sys.version_info
IS_PY313_OR_GREATER = _version.major == 3 and _version.minor >= 13


def _c_optimizations_required():
Expand Down
3 changes: 3 additions & 0 deletions src/zope/interface/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,9 @@ def update_value(aname, aval):
# __static_attributes__: Python 3.13a6+
# https://github.com/python/cpython/pull/115913
'__static_attributes__',
# __firstlineno__: Python 3.13b1+
# https://github.com/python/cpython/pull/118475
'__firstlineno__',
)
and aval is not _decorator_non_return
}
Expand Down
14 changes: 13 additions & 1 deletion src/zope/interface/tests/test_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,22 @@ def test_w_class(self):
self.assertTrue(d is advisory_testing.my_globals)

def test_inside_function_call(self):
from zope.interface._compat import IS_PY313_OR_GREATER
from zope.interface.advice import getFrameInfo
kind, module, f_locals, f_globals = getFrameInfo(sys._getframe())
self.assertEqual(kind, "function call")
self.assertTrue(f_locals is locals()) # ???

if IS_PY313_OR_GREATER:
# Python 3.13b1 implements PEP 667, which changes the type of
# ``f_locals`` from a mapping to a ``FrameLocalsProxy`` object
# while the return value of ``locals()`` is still a mapping, so
# they no longer point to the same object.
# See https://peps.python.org/pep-0667 and
# https://github.com/python/cpython/pull/115153
self.assertDictEqual(dict(f_locals), locals())
else:
self.assertTrue(f_locals is locals()) # ???

for d in module.__dict__, f_globals:
self.assertTrue(d is globals())

Expand Down

0 comments on commit adab2bd

Please sign in to comment.