Skip to content

Commit

Permalink
Merge branch 'master' into config-with-zope-product-template-5128b943
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz authored Jun 23, 2023
2 parents 87a01aa + 409d8a9 commit 88530cc
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ testenv-commands-pre = [
"{envbindir}/buildout -c {toxinidir}/buildout.cfg buildout:directory={envdir} buildout:develop={toxinidir} install alltests",
]
testenv-commands = [
"{envdir}/bin/alltests {posargs:-vc}",
"# the `layer` argument below suppresses a `ZCatalog` performance test",
"# which occasionally fails on GITHUB",
"{envdir}/bin/alltests --layer '!Products.PluginIndexes' {posargs:-vc}",
]
coverage-basepython = "python3.8"
coverage-command = "coverage run {envdir}/bin/alltests {posargs:-vc}"
Expand Down
17 changes: 17 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,27 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst
5.8.4 (unreleased)
------------------

- Disable a ``ZCatalog`` (more precisly: ``Products.PluginIndexes``)
performance test which occasionally fails on GITHUB.
For details, see
`#1136 <https://github.com/zopefoundation/Zope/issues/1136>`_.

- Restore filename on code objects of objects returned from
``App.Extensions.getObject()``. This got lost in 4.0a6.

- Update to newest compatible versions of dependencies.

- Add preliminary support for Python 3.12b2.

- Make ``mapply`` ``__signature__`` aware.
This allows to publish methods decorated via a decorator
which sets ``__signature__`` on the wrapper to specify
the signature to use.
For details, see
`#1134 <https://github.com/zopefoundation/Zope/issues/1134>`_.
Note: ``mapply`` still does not support keyword only, var positional
and var keyword parameters.


5.8.3 (2023-06-15)
------------------
Expand Down
3 changes: 2 additions & 1 deletion src/App/Extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ def getObject(module, name, reload=0):
except Exception:
raise NotFound("The specified module, '%s', "
"couldn't be opened." % module)
execcode = compile(execsrc, path, 'exec')
module_dict = {}
exec(execsrc, module_dict)
exec(execcode, module_dict)

if old is not None:
# XXX Accretive??
Expand Down
2 changes: 2 additions & 0 deletions src/App/tests/fixtures/error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file intentionally contains a SyntaxError
a = # noqa
5 changes: 5 additions & 0 deletions src/App/tests/fixtures/getObject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys


def f1():
return sys._getframe(0).f_code.co_filename
38 changes: 38 additions & 0 deletions src/App/tests/test_Extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import types
import unittest
from pathlib import Path

import App.config
from App.Extensions import getObject


class GetObjectTests(unittest.TestCase):
"""Testing ..Extensions.getObject()."""

def setUp(self):
cfg = App.config.getConfiguration()
assert not hasattr(cfg, 'extensions')
cfg.extensions = Path(__file__).parent / 'fixtures'

def tearDown(self):
cfg = App.config.getConfiguration()
del cfg.extensions

def test_Extensions__getObject__1(self):
"""Check that "getObject" returns the requested function and ...
that its code object has the path set.
"""
obj = getObject('getObject', 'f1')
self.assertIsInstance(obj, types.FunctionType)
self.assertEqual(obj.__name__, 'f1')
path = obj()
self.assertTrue(
path.endswith(str(Path('App/tests/fixtures/getObject.py'))))

def test_Extensions__getObject__2(self):
"""It raises a SyntaxError if necessary."""
try:
getObject('error', 'f1')
except SyntaxError as e:
self.assertEqual(str(e), 'invalid syntax (error.py, line 2)')
19 changes: 16 additions & 3 deletions src/ZPublisher/mapply.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
##############################################################################
"""Provide an apply-like facility that works with any mapping object
"""
from inspect import getfullargspec

import zope.publisher.publish


Expand Down Expand Up @@ -50,9 +52,20 @@ def mapply(object, positional=(), keyword={},
if maybe:
return object
raise
code = f.__code__
defaults = f.__defaults__
names = code.co_varnames[count:code.co_argcount]
if hasattr(f, "__signature__"):
# The function has specified the signature to use
# (likely via a decorator)
# We use ``getfullargspec`` because it packages
# the signature information in the way we need it here.
# Should the function get deprecated, we could do the
# packaging ourselves
argspec = getfullargspec(f)
defaults = argspec.defaults
names = argspec.args[count:]
else:
code = f.__code__
defaults = f.__defaults__
names = code.co_varnames[count:code.co_argcount]

nargs = len(names)
if positional:
Expand Down
14 changes: 14 additions & 0 deletions src/ZPublisher/tests/test_mapply.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,17 @@ class NoCallButAcquisition(Acquisition.Implicit):

ob = NoCallButAcquisition().__of__(Root())
self.assertRaises(TypeError, mapply, ob, (), {})

def testFunctionWithSignature(self):
from inspect import Parameter
from inspect import Signature

def f(*args, **kw):
return args, kw

f.__signature__ = Signature(
(Parameter("a", Parameter.POSITIONAL_OR_KEYWORD),
Parameter("b", Parameter.POSITIONAL_OR_KEYWORD, default="b")))

self.assertEqual(mapply(f, ("a",), {}), (("a", "b"), {}))
self.assertEqual(mapply(f, (), {"a": "A", "b": "B"}), (("A", "B"), {}))
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ setenv =
commands_pre =
{envbindir}/buildout -c {toxinidir}/buildout.cfg buildout:directory={envdir} buildout:develop={toxinidir} install alltests
commands =
{envdir}/bin/alltests {posargs:-vc}
# the `layer` argument below suppresses a `ZCatalog` performance test
# which occasionally fails on GITHUB
{envdir}/bin/alltests --layer '!Products.PluginIndexes' {posargs:-vc}

[testenv:pre-commit]
basepython = python3
Expand Down

0 comments on commit 88530cc

Please sign in to comment.