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

Allow InstancePropertyHelper to accept properties with names on Python 3.13+ #3762

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
- "3.13-dev"
- "pypy-3.8"
os:
- "ubuntu-20.04"
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def readfile(name):
tests_require = [
'webtest >= 1.3.1', # py3 compat
'zope.component >= 4.0', # py3 compat
'legacy-cgi;python_version>="3.13"', # needed by webob, Pylons/webob#437
]

docs_extras = [
Expand Down
3 changes: 2 additions & 1 deletion src/pyramid/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def make_property(cls, callable, name=None, reify=False):
if name is None:
if not hasattr(callable, '__name__'):
raise ValueError(
'missing __name__, must specify "name" for property'
'missing __name__, must specify "name" for property '
'on Python < 3.13'
)
name = callable.__name__
name = get_callable_name(name)
Expand Down
28 changes: 22 additions & 6 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,21 @@ def worker(obj):

def test_property_without_name(self):
def worker(obj): # pragma: no cover
pass
return obj.bar

foo = Dummy()
helper = self._getTargetClass()
self.assertRaises(
ValueError, helper.set_property, foo, property(worker)
)
if sys.version_info < (3, 13):
self.assertRaises(
ValueError, helper.set_property, foo, property(worker)
)
else:
# Since Python 3.13, the name of the property is automatic
helper.set_property(foo, property(worker))
foo.bar = 1
self.assertEqual(1, foo.worker)
foo.bar = 2
self.assertEqual(2, foo.worker)

def test_property_with_name(self):
def worker(obj):
Expand Down Expand Up @@ -272,10 +280,18 @@ def worker(obj):

def test_property_without_name(self):
def worker(obj): # pragma: no cover
pass
return obj.bar

foo = self._makeOne()
self.assertRaises(ValueError, foo.set_property, property(worker))
if sys.version_info < (3, 13):
self.assertRaises(ValueError, foo.set_property, property(worker))
else:
# Since Python 3.13, the name of the property is automatic
foo.set_property(property(worker))
foo.bar = 1
self.assertEqual(1, foo.worker)
foo.bar = 2
self.assertEqual(2, foo.worker)

def test_property_with_name(self):
def worker(obj):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist =
lint,
py38,py39,py310,py311,py312,pypy3,
py38,py39,py310,py311,py312,py313,pypy3,
py312-cover,coverage,
docs

Expand Down
Loading