@@ -43,6 +43,7 @@ def __repr__(self):
4343 def __getitem__ (self , item ):
4444 if self ._name == "Intersection" :
4545 return _IntersectionGenericAlias (self , item )
46+ return None
4647
4748
4849if TYPE_CHECKING :
@@ -61,7 +62,7 @@ def __getitem__(self, item):
6162
6263T = TypeVar ("T" )
6364T_co = TypeVar ("T_co" , covariant = True )
64- T_cont = TypeVar ("T_cont " , contravariant = True )
65+ T_contra = TypeVar ("T_contra " , contravariant = True )
6566Fn = TypeVar ("Fn" , bound = Function )
6667
6768
@@ -179,11 +180,11 @@ def _is_subclass(cls, subclass: object) -> TypeGuard[_ReifiedGenericMetaclass[T]
179180 "origin" type (ie. without the generics) is a subclass of this reified generic
180181 """
181182 # could be any random instance, check it's a reified generic first:
182- return type .__instancecheck__ ( # type: ignore[no-any-expr]
183- _ReifiedGenericMetaclass , # type: ignore[no-any-expr]
183+ return type .__instancecheck__ (
184+ _ReifiedGenericMetaclass ,
184185 subclass ,
185186 # then check that the instance is an instance of this particular reified generic:
186- ) and type .__subclasscheck__ ( # type: ignore[no-any-expr]
187+ ) and type .__subclasscheck__ (
187188 cls ._orig_class (),
188189 # https://github.com/python/mypy/issues/11671
189190 cast ( # pylint:disable=protected-access
@@ -315,9 +316,7 @@ def __class_getitem__( # type: ignore[no-any-decorated]
315316 orig_type_vars = (
316317 cls .__type_vars__
317318 if hasattr (cls , "__type_vars__" )
318- else cast (
319- Tuple [TypeVar , ...], cls .__parameters__ # type: ignore[attr-defined]
320- )
319+ else cast (Tuple [TypeVar , ...], cls .__parameters__ )
321320 )
322321
323322 # add any reified generics from the superclass if there is one
@@ -335,13 +334,13 @@ def __class_getitem__( # type: ignore[no-any-decorated]
335334 cls , # make the copied class extend the original so normal instance checks work
336335 ),
337336 # TODO: proper type
338- dict ( # type: ignore[no-any-expr]
339- __reified_generics__ = tuple ( # type: ignore[no-any-expr]
337+ { # type: ignore[no-any-expr]
338+ " __reified_generics__" : tuple ( # type: ignore[no-any-expr]
340339 _type_convert (t ) for t in items # type: ignore[unused-ignore, no-any-expr]
341340 ),
342- _orig_type_vars = orig_type_vars ,
343- __type_vars__ = _collect_parameters (items ), # type: ignore[name-defined]
344- ) ,
341+ " _orig_type_vars" : orig_type_vars ,
342+ " __type_vars__" : _collect_parameters (items ), # type: ignore[name-defined]
343+ } ,
345344 )
346345 # can't set it in the dict above otherwise __init_subclass__ overwrites it
347346 ReifiedGenericCopy ._can_do_instance_and_subclass_checks_without_generics = ( # pylint:disable=protected-access
@@ -363,6 +362,7 @@ def __init_subclass__(cls) -> None: # pylint:disable=arguments-differ
363362 _UnionTypes = (OldUnionType ,)
364363 _Forms : TypeAlias = Union [type , _SpecialForm ]
365364
365+
366366# TODO: make this work with any "form", not just unions
367367# should be (form: TypeForm, forminfo: TypeForm)
368368# TODO: form/forminfo can include _UnionGenericAlias
@@ -421,7 +421,8 @@ def Untyped(self: _SpecialForm, parameters: object) -> NoReturn:
421421 raise TypeError (f"{ self } is not subscriptable" )
422422
423423 else :
424- Untyped : Final = _BasedSpecialForm (
424+ # old version had the doc argument
425+ Untyped : Final = _BasedSpecialForm ( # pylint:disable=unexpected-keyword-arg
425426 "Untyped" ,
426427 doc = (
427428 "Special type indicating that something isn't typed.\n This is more"
@@ -432,8 +433,8 @@ def Untyped(self: _SpecialForm, parameters: object) -> NoReturn:
432433if not TYPE_CHECKING :
433434
434435 class _IntersectionGenericAlias (_GenericAlias , _root = True ):
435- def copy_with (self , params ):
436- return Intersection [params ]
436+ def copy_with (self , args ):
437+ return Intersection [args ]
437438
438439 def __eq__ (self , other ):
439440 if not isinstance (other , _IntersectionGenericAlias ):
@@ -450,9 +451,10 @@ def __subclasscheck__(self, cls):
450451 for arg in self .__args__ :
451452 if issubclass (cls , arg ):
452453 return True
454+ return False
453455
454456 def __reduce__ (self ):
455- func , (origin , args ) = super ().__reduce__ ()
457+ func , (_ , args ) = super ().__reduce__ ()
456458 return func , (Intersection , args )
457459
458460 if sys .version_info > (3 , 9 ):
@@ -499,6 +501,9 @@ def Intersection(self, parameters):
499501 return _IntersectionGenericAlias (self , parameters )
500502
501503 else :
502- Intersection = _BasedSpecialForm ("Intersection" , doc = "" )
504+ # old version had the doc argument
505+ Intersection = _BasedSpecialForm ( # pylint:disable=unexpected-keyword-arg
506+ "Intersection" , doc = ""
507+ )
503508else :
504509 Intersection : _SpecialForm
0 commit comments