@@ -501,7 +501,9 @@ def instance_init(self, obj: t.Any) -> None:
501501# see https://peps.python.org/pep-0673/#use-in-generic-classes
502502# Self = t.TypeVar("Self", bound="TraitType[Any, Any]")
503503if t .TYPE_CHECKING :
504- from typing_extensions import Literal , Self
504+ from typing import Literal
505+
506+ from typing_extensions import Self
505507
506508 K = TypeVar ("K" , default = str )
507509 V = TypeVar ("V" , default = t .Any )
@@ -2370,7 +2372,7 @@ class ForwardDeclaredInstance(ForwardDeclaredMixin, Instance[T]):
23702372 """
23712373
23722374
2373- class This (ClassBasedTraitType [t . Optional [ T ], t . Optional [ T ] ]):
2375+ class This (ClassBasedTraitType [T | None , T | None ]):
23742376 """A trait for instances of the class containing this trait.
23752377
23762378 Because how how and when class bodies are executed, the ``This``
@@ -2483,7 +2485,7 @@ def from_string(self, s: str) -> t.Any:
24832485# -----------------------------------------------------------------------------
24842486
24852487
2486- class Any (TraitType [t .Optional [ t . Any ] , t .Optional [ t . Any ] ]):
2488+ class Any (TraitType [t .Any | None , t .Any | None ]):
24872489 """A trait which allows any value."""
24882490
24892491 if t .TYPE_CHECKING :
@@ -2582,7 +2584,7 @@ def _validate_bounds(
25822584 return value
25832585
25842586
2585- # I = t.TypeVar('I', t.Optional[ int] , int)
2587+ # I = t.TypeVar('I', int | None , int)
25862588
25872589
25882590class Int (TraitType [G , S ]):
@@ -2824,7 +2826,7 @@ def validate(self, obj: t.Any, value: t.Any) -> G:
28242826 return _validate_bounds (self , obj , value ) # type:ignore[no-any-return]
28252827
28262828
2827- class Complex (TraitType [complex , t . Union [ complex , float , int ] ]):
2829+ class Complex (TraitType [complex , complex | float | int ]):
28282830 """A trait for complex numbers."""
28292831
28302832 default_value = 0.0 + 0.0j
@@ -3332,7 +3334,7 @@ def validate(self, obj: t.Any, value: t.Any) -> G:
33323334 choices = self .values or []
33333335 matches = [match_func (value , conv_func (c )) for c in choices ] # type:ignore[no-untyped-call]
33343336 if sum (matches ) == 1 :
3335- for v , m in zip (choices , matches ):
3337+ for v , m in zip (choices , matches , strict = True ):
33363338 if m :
33373339 return v
33383340
@@ -3580,16 +3582,16 @@ def item_from_string(self, s: str, index: int | None = None) -> T | str:
35803582 return s
35813583
35823584
3583- class List (Container [t . List [T ]]):
3585+ class List (Container [list [T ]]):
35843586 """An instance of a Python list."""
35853587
35863588 klass = list # type:ignore[assignment]
35873589 _cast_types : t .Any = (tuple ,)
35883590
35893591 def __init__ (
35903592 self ,
3591- trait : t . List [T ] | t . Tuple [T ] | t . Set [T ] | Sentinel | TraitType [T , t .Any ] | None = None ,
3592- default_value : t . List [T ] | t . Tuple [T ] | t . Set [T ] | Sentinel | None = Undefined ,
3593+ trait : list [T ] | tuple [T ] | set [T ] | Sentinel | TraitType [T , t .Any ] | None = None ,
3594+ default_value : list [T ] | tuple [T ] | set [T ] | Sentinel | None = Undefined ,
35933595 minlen : int = 0 ,
35943596 maxlen : int = sys .maxsize ,
35953597 ** kwargs : t .Any ,
@@ -3645,7 +3647,7 @@ def set(self, obj: t.Any, value: t.Any) -> None:
36453647 return super ().set (obj , value )
36463648
36473649
3648- class Set (Container [t . Set [t .Any ]]):
3650+ class Set (Container [set [t .Any ]]):
36493651 """An instance of a Python set."""
36503652
36513653 klass = set
@@ -3720,7 +3722,7 @@ def default_value_repr(self) -> str:
37203722 return "{" + list_repr [1 :- 1 ] + "}"
37213723
37223724
3723- class Tuple (Container [t . Tuple [t .Any , ...]]):
3725+ class Tuple (Container [tuple [t .Any , ...]]):
37243726 """An instance of a Python tuple."""
37253727
37263728 klass = tuple
@@ -3826,7 +3828,7 @@ def validate_elements(self, obj: t.Any, value: t.Any) -> t.Any:
38263828 raise TraitError (e )
38273829
38283830 validated = []
3829- for trait , v in zip (self ._traits , value ):
3831+ for trait , v in zip (self ._traits , value , strict = True ):
38303832 try :
38313833 v = trait ._validate (obj , v )
38323834 except TraitError as error :
@@ -4188,7 +4190,7 @@ def from_string(self, s: str) -> G:
41884190 return (ip , port ) # type:ignore[return-value]
41894191
41904192
4191- class CRegExp (TraitType [" re.Pattern[t.Any]" , t . Union [ " re.Pattern[t.Any]" , str ] ]):
4193+ class CRegExp (TraitType [re .Pattern [t .Any ], re .Pattern [t .Any ] | str ]):
41924194 """A casting compiled regular expression trait.
41934195
41944196 Accepts both strings and compiled regular expressions. The resulting
0 commit comments