Skip to content

Commit

Permalink
Update Python version support.
Browse files Browse the repository at this point in the history
  • Loading branch information
icemac committed Aug 5, 2024
1 parent ca7a839 commit feed7be
Show file tree
Hide file tree
Showing 18 changed files with 479 additions and 499 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ def read(*rnames):
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Framework :: Zope :: 3",
"Topic :: Software Development :: Libraries :: Python Modules",
],
python_requires='>=3.7',
python_requires='>=3.8',
include_package_data=True,
zip_safe=False,
extras_require={
Expand Down
56 changes: 28 additions & 28 deletions src/zope/schema/_bootstrapfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from zope.schema._bootstrapinterfaces import WrongType


class _NotGiven(object):
class _NotGiven:

def __repr__(self): # pragma: no cover
return "<Not Given>"
Expand All @@ -64,7 +64,7 @@ def __repr__(self): # pragma: no cover
_NotGiven = _NotGiven()


class ValidatedProperty(object):
class ValidatedProperty:

def __init__(self, name, check=None, allow_none=False):
self._name = name
Expand Down Expand Up @@ -123,7 +123,7 @@ def getFields(schema):
return fields


class _DocStringHelpers(object):
class _DocStringHelpers:
# Namespace object to hold methods related to ReST formatting
# docstrings

Expand Down Expand Up @@ -164,19 +164,19 @@ def make_class_directive(kind):
if mod in ('zope.schema._bootstrapfields', 'zope.schema._field'):
mod = 'zope.schema'
mod += '.' if mod else ''
return ':class:`%s%s`' % (mod, kind.__name__)
return ':class:`{}{}`'.format(mod, kind.__name__)

@classmethod
def make_field(cls, name, value):
return ":%s: %s" % (name, value)
return ":{}: {}".format(name, value)

@classmethod
def make_class_field(cls, name, kind):
if isinstance(kind, (type, InterfaceClass)):
return cls.make_field(name, cls.make_class_directive(kind))
if not isinstance(kind, tuple): # pragma: no cover
raise TypeError(
"make_class_field() can't handle kind %r" % (kind,))
"make_class_field() can't handle kind {!r}".format(kind))
return cls.make_field(
name,
', '.join([cls.make_class_directive(t) for t in kind]))
Expand Down Expand Up @@ -213,7 +213,7 @@ class Field(Attribute):
interface = None
_Element__tagged_values = None

def __init__(self, title=u'', description=u'', __name__='',
def __init__(self, title='', description='', __name__='',
required=True, readonly=False, constraint=None, default=None,
defaultFactory=None, missing_value=__missing_value_marker):
"""Pass in field values as keyword parameters.
Expand Down Expand Up @@ -247,18 +247,18 @@ def __init__(self, title=u'', description=u'', __name__='',
# strings, but don't overwrite the original, we need to
# preserve it (it could be a MessageID).
doc_description = '\n'.join(
_DocStringHelpers.docstring_to_lines(description or u'')[:-1]
_DocStringHelpers.docstring_to_lines(description or '')[:-1]
)

if title:
if doc_description:
__doc__ = "%s\n\n%s" % (title, doc_description)
__doc__ = "{}\n\n{}".format(title, doc_description)
else:
__doc__ = title
elif description:
__doc__ = doc_description

super(Field, self).__init__(__name__, __doc__)
super().__init__(__name__, __doc__)
self.title = title
self.description = description
self.required = required
Expand Down Expand Up @@ -420,7 +420,7 @@ def getExtraDocLines(self):
return lines

def getDoc(self):
doc = super(Field, self).getDoc()
doc = super().getDoc()
lines = _DocStringHelpers.docstring_to_lines(doc)
lines += self.getExtraDocLines()
lines.append('')
Expand All @@ -431,7 +431,7 @@ def getDoc(self):
class Container(Field):

def _validate(self, value):
super(Container, self)._validate(value)
super()._validate(value)

if not hasattr(value, '__contains__'):
try:
Expand All @@ -446,7 +446,7 @@ def _validate(self, value):
class Iterable(Container):

def _validate(self, value):
super(Iterable, self)._validate(value)
super()._validate(value)

# See if we can get an iterator for it
try:
Expand All @@ -455,7 +455,7 @@ def _validate(self, value):
raise NotAnIterator(value).with_field_and_value(self, value)


class Orderable(object):
class Orderable:
"""Values of ordered fields can be sorted.
They can be restricted to a range of values.
Expand All @@ -473,7 +473,7 @@ def __init__(self, min=None, max=None, default=None, **kw):
self.min = None
self.max = None

super(Orderable, self).__init__(**kw)
super().__init__(**kw)

# Now really set min and max
self.min = min
Expand All @@ -484,7 +484,7 @@ def __init__(self, min=None, max=None, default=None, **kw):
self.default = default

def _validate(self, value):
super(Orderable, self)._validate(value)
super()._validate(value)

if self.min is not None and value < self.min:
raise TooSmall(value, self.min).with_field_and_value(self, value)
Expand All @@ -493,7 +493,7 @@ def _validate(self, value):
raise TooBig(value, self.max).with_field_and_value(self, value)


class MinMaxLen(object):
class MinMaxLen:
"""Expresses constraints on the length of a field.
MinMaxLen is a mixin used in combination with Field.
Expand All @@ -504,10 +504,10 @@ class MinMaxLen(object):
def __init__(self, min_length=0, max_length=None, **kw):
self.min_length = min_length
self.max_length = max_length
super(MinMaxLen, self).__init__(**kw)
super().__init__(**kw)

def _validate(self, value):
super(MinMaxLen, self)._validate(value)
super()._validate(value)

if self.min_length is not None and len(value) < self.min_length:
raise TooShort(value, self.min_length).with_field_and_value(
Expand All @@ -527,7 +527,7 @@ class Text(MinMaxLen, Field):
def __init__(self, *args, **kw):
self.unicode_normalization = kw.pop(
'unicode_normalization', self.unicode_normalization)
super(Text, self).__init__(*args, **kw)
super().__init__(*args, **kw)

def fromUnicode(self, value):
"""
Expand Down Expand Up @@ -581,7 +581,7 @@ def set(self, context, value):
"""
if value is self.UNCHANGED_PASSWORD:
return
super(Password, self).set(context, value)
super().set(context, value)

def validate(self, value):
try:
Expand All @@ -591,7 +591,7 @@ def validate(self, value):
if value is self.UNCHANGED_PASSWORD and existing:
# Allow the UNCHANGED_PASSWORD value, if a password is set already
return
return super(Password, self).validate(value)
return super().validate(value)


@implementer(IFromUnicode, IFromBytes)
Expand Down Expand Up @@ -994,7 +994,7 @@ class Decimal(Number):
class _ObjectsBeingValidated(threading.local):

def __init__(self):
super(_ObjectsBeingValidated, self).__init__()
super().__init__()
self.ids_being_validated = set()


Expand Down Expand Up @@ -1123,16 +1123,16 @@ def __init__(self, schema=_NotGiven, **kw):

self.schema = schema
self.validate_invariants = kw.pop('validate_invariants', True)
super(Object, self).__init__(**kw)
super().__init__(**kw)

def getExtraDocLines(self):
lines = super(Object, self).getExtraDocLines()
lines = super().getExtraDocLines()
lines.append(_DocStringHelpers.make_class_field(
"Must Provide", self.schema))
return lines

def _validate(self, value):
super(Object, self)._validate(value)
super()._validate(value)

# schema has to be provided by value
if not self.schema.providedBy(value):
Expand Down Expand Up @@ -1173,11 +1173,11 @@ def set(self, object, value):
# The event subscribers are allowed to replace the object, thus we need
# to replace our previous value.
value = event.object
super(Object, self).set(object, value)
super().set(object, value)


@implementer(IBeforeObjectAssignedEvent)
class BeforeObjectAssignedEvent(object):
class BeforeObjectAssignedEvent:
"""An object is going to be assigned to an attribute on another object."""

def __init__(self, object, name, context):
Expand Down
14 changes: 7 additions & 7 deletions src/zope/schema/_bootstrapinterfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __eq__(self, other):
__hash__ = zope.interface.Invalid.__hash__ # python3

def __repr__(self): # pragma: no cover
return '%s(%s)' % (
return '{}({})'.format(
self.__class__.__name__,
', '.join(repr(arg) for arg in self.args))

Expand Down Expand Up @@ -129,7 +129,7 @@ def __init__(self, value=None, bound=None, *args):
"""
OutOfBounds(value, bound)
"""
super(OutOfBounds, self).__init__(value, bound, *args)
super().__init__(value, bound, *args)
self.value = value
self.bound = bound

Expand Down Expand Up @@ -206,7 +206,7 @@ def __init__(self, errors=None, name=None, *args):
.. versionchanged:: 4.7.0
Added named arguments to the constructor, and the `errors` property.
"""
super(WrongContainedType, self).__init__(errors, name, *args)
super().__init__(errors, name, *args)
self.errors = errors


Expand All @@ -230,7 +230,7 @@ def __init__(self, errors=None, name=None, schema_errors=None,
.. versionchanged:: 4.7.0
Added named arguments to the constructor.
"""
super(SchemaNotCorrectlyImplemented, self).__init__(
super().__init__(
errors, name, *args)
self.schema_errors = schema_errors
self.invariant_errors = invariant_errors
Expand All @@ -254,7 +254,7 @@ def __init__(self, schema=None, value=None, *args):
.. versionchanged:: 4.7.0
Added named arguments to the constructor and the `schema` property.
"""
super(SchemaNotProvided, self).__init__(schema, value, *args)
super().__init__(schema, value, *args)
self.schema = schema
self.value = value

Expand All @@ -276,7 +276,7 @@ class NotAnInterface(WrongType, SchemaNotProvided):
expected_type = IInterface

def __init__(self, value, name):
super(NotAnInterface, self).__init__(value, IInterface, name)
super().__init__(value, IInterface, name)


class IFromUnicode(zope.interface.Interface):
Expand Down Expand Up @@ -348,7 +348,7 @@ def validate(value):
"""


class NO_VALUE(object):
class NO_VALUE:
def __repr__(self): # pragma: no cover
return '<NO_VALUE>'

Expand Down
Loading

0 comments on commit feed7be

Please sign in to comment.