1010.. TODO: This module is big enough it should be factored into a package and sub-modules.
1111"""
1212
13+ import collections .abc as abcs
1314# stdlib imports
1415import numbers
1516import re
17+ from typing import Any
1618
17- import collections .abc as abcs
18-
19-
19+ import zope .interface .common .idatetime
2020from zope import interface
2121from zope import schema
22+ from zope .cachedescriptors .property import Lazy
2223from zope .deferredimport import deprecatedFrom
23-
2424from zope .event import notify
25- import zope .interface .common .idatetime
26- from zope .cachedescriptors .property import Lazy
27-
28- from zope .schema import interfaces as sch_interfaces
29- from zope .schema .interfaces import IFromBytes
30- from zope .schema .interfaces import IFromUnicode
31- from zope .schema .interfaces import InvalidValue
32-
3325from zope .schema import Bool
3426from zope .schema import Choice
27+ from zope .schema import Complex
3528from zope .schema import Date
3629from zope .schema import Datetime
3730from zope .schema import Decimal
3831from zope .schema import Dict
3932from zope .schema import FrozenSet
33+ from zope .schema import Integral
4034from zope .schema import Iterable
4135from zope .schema import List
4236from zope .schema import Mapping
4337from zope .schema import MutableMapping
4438from zope .schema import MutableSequence
39+ from zope .schema import Object as _ObjectBase
40+ from zope .schema import Rational
41+ from zope .schema import Real
4542from zope .schema import Sequence
4643from zope .schema import Set
4744from zope .schema import Text
4845from zope .schema import TextLine
4946from zope .schema import Timedelta
5047from zope .schema import Tuple
51- from zope .schema import Object as _ObjectBase
52-
53- from zope .schema import Complex
54- from zope .schema import Real
55- from zope .schema import Rational
56- from zope .schema import Integral
48+ from zope .schema import interfaces as sch_interfaces
49+ from zope .schema .interfaces import IFromBytes
50+ from zope .schema .interfaces import IFromUnicode
51+ from zope .schema .interfaces import InvalidValue
5752
5853from nti .schema import MessageFactory as _
5954from nti .schema .interfaces import BeforeDictAssignedEvent
6863from nti .schema .interfaces import IVariant
6964from nti .schema .interfaces import VariantValidationError
7065
71-
7266__docformat__ = "restructuredtext en"
7367
7468# Re-export some things as part of our public API so we can
@@ -286,7 +280,7 @@ def _fixup_too_long(self, e, value):
286280
287281 def _validate (self , value ):
288282 try :
289- super ()._validate (value )
283+ super ()._validate (value ) # type:ignore[misc]
290284 except sch_interfaces .WrongType as e :
291285 assert e .expected_type is not None , "The expected_type should be provided"
292286 raise
@@ -431,7 +425,7 @@ class Variant(FieldValidationMixin, schema.Field):
431425 would be raised. Now, constructing the variant will raise a ``RequiredMissing``.
432426 """
433427
434- fields = ()
428+ fields : abcs . Sequence [ schema . Field ] = ()
435429
436430 def __init__ (self , fields , variant_raise_when_schema_provided = False , ** kwargs ):
437431 """
@@ -510,7 +504,7 @@ def _validate(self, value):
510504 raise VariantValidationError (self , value , errors )
511505 finally :
512506 # break cycles
513- e = errors = None
507+ del errors
514508
515509 def fromObject (self , obj ):
516510 """
@@ -561,7 +555,7 @@ def fromObject(self, obj):
561555 raise VariantValidationError (self , obj , errors )
562556 finally :
563557 # break cycles
564- ex = errors = None
558+ del errors
565559
566560 _EVENT_TYPES = (
567561 (str , BeforeTextAssignedEvent ),
@@ -672,8 +666,9 @@ def fromBytes(self, value):
672666 return self .fromUnicode (value .decode ('utf-8' ))
673667
674668
675- _not_stripped = r"^\s|\s$" # space at either beginning or end
676- _not_stripped = re .compile (_not_stripped ).search
669+ _not_stripped = re .compile (
670+ r"^\s|\s$" # space at either beginning or end
671+ ).search
677672
678673
679674def _is_stripped (value ):
@@ -764,7 +759,7 @@ class _ValueTypeAddingDocMixin(object):
764759 """
765760
766761 def getExtraDocLines (self ):
767- lines = super ().getExtraDocLines ()
762+ lines = super ().getExtraDocLines () # type:ignore[misc]
768763 accept_types = getattr (self , 'accept_types' , None )
769764 if accept_types :
770765 # Private helper. If it goes away or changes, making sphinx docs will
@@ -799,8 +794,13 @@ class ListOrTuple(IndexedIterable):
799794
800795@interface .implementer (IFromObject )
801796class _SequenceFromObjectMixin (object ):
802- accept_types = None
797+ accept_types : abcs . Sequence [ type ] | None = None
803798 _default_type = list
799+ value_type : schema .Field
800+ _type : type | abcs .Sequence [type ] | None
801+ missing_value : Any
802+ required : bool
803+ __name__ : str
804804
805805 def __init__ (self , * args , ** kwargs ):
806806 super ().__init__ (* args , ** kwargs )
@@ -844,7 +844,7 @@ def fromObject(self, context):
844844 return context
845845
846846 check_type = self .accept_types or self ._type
847- if check_type is not None and not isinstance (context , check_type ):
847+ if check_type is not None and not isinstance (context , check_type ): # type:ignore[arg-type]
848848 raise sch_interfaces .WrongType (context , check_type ).with_field_and_value (self , context )
849849
850850 result = self ._do_fromObject (context )
@@ -864,6 +864,7 @@ def __getattr__(self, name):
864864
865865
866866class _MapFromObjectMixin (_SequenceFromObjectMixin ):
867+ key_type : schema .Field
867868
868869 def __init__ (self , * args , ** kwargs ):
869870 super ().__init__ (* args , ** kwargs )
@@ -891,7 +892,7 @@ def __getattr__(self, name):
891892 return getattr (self .__field , name )
892893
893894
894- class ListOrTupleFromObject (_SequenceFromObjectMixin , ListOrTuple ):
895+ class ListOrTupleFromObject (_SequenceFromObjectMixin , ListOrTuple ): # type:ignore[misc]
895896 """
896897 The ``value_type`` MUST be a :class:`Variant`, or more generally,
897898 something supporting :class:`IFromObject`, :class:`IFromUnicode`
0 commit comments