@@ -498,7 +498,7 @@ def supports(
498
498
499
499
def instance (
500
500
self ,
501
- type_ : Optional [_NewInstanceType ],
501
+ type_argument : Optional [_NewInstanceType ],
502
502
* ,
503
503
# TODO: at one point I would like to remove `is_protocol`
504
504
# and make this function decide whether this type is protocol or not.
@@ -510,27 +510,26 @@ def instance(
510
510
The only setting we provide is ``is_protocol`` which is required
511
511
when passing protocols. See our ``mypy`` plugin for that.
512
512
"""
513
- if type_ is None : # `None` is a special case
514
- type_ = type (None ) # type: ignore
513
+ typ = type_argument or type (None ) # `None` is a special case
515
514
516
515
# That's how we check for generics,
517
516
# generics that look like `List[int]` or `set[T]` will fail this check,
518
517
# because they are `_GenericAlias` instance,
519
518
# which raises an exception for `__isinstancecheck__`
520
- isinstance (object (), type_ ) # type: ignore
519
+ isinstance (object (), typ )
521
520
522
521
def decorator (implementation ):
523
522
container = self ._protocols if is_protocol else self ._instances
524
- container [type_ ] = implementation # type: ignore
523
+ container [typ ] = implementation
525
524
526
- if isinstance (type_ . __instancecheck__ , MethodType ): # noqa: WPS609
525
+ if isinstance (getattr ( typ , ' __instancecheck__' , None ), MethodType ):
527
526
# This means that this type has `__instancecheck__` defined,
528
527
# which allows dynamic checks of what `isinstance` of this type.
529
528
# That's why we also treat this type as a protocol.
530
- self ._protocols [type_ ] = implementation # type: ignore
529
+ self ._protocols [typ ] = implementation
531
530
532
531
if self ._cache_token is None : # pragma: no cover
533
- if getattr (type_ , '__abstractmethods__' , None ):
532
+ if getattr (typ , '__abstractmethods__' , None ):
534
533
self ._cache_token = get_cache_token ()
535
534
536
535
self ._dispatch_cache .clear ()
0 commit comments