@@ -967,18 +967,37 @@ def evolve_function_sig_callback(ctx: mypy.plugin.FunctionSigContext) -> Callabl
967
967
return ctx .default_signature # evolve(Any, ....) -> Any
968
968
# We stringify it first, so that TypeVars maintain their name.
969
969
inst_type_str = format_type_bare (inst_type )
970
- upper_bound = inst_type .upper_bound if isinstance (inst_type , TypeVarType ) else inst_type
971
- if not (
972
- isinstance (upper_bound , Instance )
973
- and (attrs_init_type := _get_attrs_init_type (upper_bound ))
974
- ):
975
- ctx .api .fail (
976
- f'Argument 1 to "evolve" has incompatible type "{ inst_type_str } "; expected an attrs class' ,
977
- ctx .context ,
978
- )
979
- return ctx .default_signature
970
+ if isinstance (inst_type , TypeVarType ):
971
+ attrs_type = inst_type .upper_bound
972
+ if not isinstance (attrs_type , Instance ):
973
+ ctx .api .fail (
974
+ f'Argument 1 to "evolve" has a variable type "{ inst_type_str } " with unexpected upper bounds' ,
975
+ ctx .context ,
976
+ )
977
+ return ctx .default_signature # TODO: is this possible?
978
+ attrs_init_type = _get_attrs_init_type (attrs_type )
979
+ if attrs_init_type is None :
980
+ ctx .api .fail (
981
+ f'Argument 1 to "evolve" has a variable type "{ inst_type_str } " not bound to an attrs class' ,
982
+ ctx .context ,
983
+ )
984
+ return ctx .default_signature
985
+ else :
986
+ attrs_type = inst_type
987
+ if not isinstance (attrs_type , Instance ):
988
+ ctx .api .fail (
989
+ f'Argument 1 to "evolve" has incompatible type "{ inst_type_str } "' , ctx .context
990
+ )
991
+ return ctx .default_signature # TODO: is this possible?
992
+ attrs_init_type = _get_attrs_init_type (attrs_type )
993
+ if attrs_init_type is None :
994
+ ctx .api .fail (
995
+ f'Argument 1 to "evolve" has incompatible type "{ inst_type_str } "; expected an attrs class' ,
996
+ ctx .context ,
997
+ )
998
+ return ctx .default_signature # TODO: is this possible?
980
999
981
- attrs_init_type = expand_type_by_instance (attrs_init_type , upper_bound )
1000
+ attrs_init_type = expand_type_by_instance (attrs_init_type , attrs_type )
982
1001
983
1002
# AttrClass.__init__ has the following signature (or similar, if having kw-only & defaults):
984
1003
# def __init__(self, attr1: Type1, attr2: Type2) -> None:
0 commit comments