|
191 | 191 | main:11: error: Instance "builtins.list[builtins.int]" does not match inferred type "main.SomeDelegate"
|
192 | 192 | main:11: error: Only a single argument can be applied to `.instance`
|
193 | 193 | main:11: error: Regular type "builtins.str*" passed as a protocol
|
| 194 | +
|
| 195 | +
|
| 196 | +- case: typeclass_concrete_generic_delegate_and_tuple1 |
| 197 | + disable_cache: false |
| 198 | + main: | |
| 199 | + from typing import Tuple |
| 200 | + from classes import typeclass |
| 201 | +
|
| 202 | + class UserTupleMeta(type): |
| 203 | + def __instancecheck__(cls, arg: object) -> bool: |
| 204 | + try: |
| 205 | + return ( |
| 206 | + isinstance(arg, tuple) and |
| 207 | + isinstance(arg[0], str) and |
| 208 | + isinstance(arg[1], bool) |
| 209 | + ) |
| 210 | + except IndexError: |
| 211 | + return False |
| 212 | +
|
| 213 | + class UserTuple(Tuple[str, bool], metaclass=UserTupleMeta): |
| 214 | + ... |
| 215 | +
|
| 216 | + @typeclass |
| 217 | + def get_name(instance) -> str: |
| 218 | + ... |
| 219 | +
|
| 220 | + @get_name.instance(delegate=UserTuple) |
| 221 | + def _get_name_user_dict(instance: Tuple[str, bool]) -> str: |
| 222 | + return instance[0] |
| 223 | +
|
| 224 | +
|
| 225 | + get_name(('a', True)) # ok |
| 226 | +
|
| 227 | + get_name(()) |
| 228 | + get_name(('a', 'b', 'c')) |
| 229 | + get_name(('a', 1)) |
| 230 | + out: | |
| 231 | + main:29: error: Argument 1 to "get_name" has incompatible type "Tuple[]"; expected "Tuple[str, bool]" |
| 232 | + main:30: error: Argument 1 to "get_name" has incompatible type "Tuple[str, str, str]"; expected "Tuple[str, bool]" |
| 233 | + main:31: error: Argument 1 to "get_name" has incompatible type "Tuple[str, int]"; expected "Tuple[str, bool]" |
| 234 | +
|
| 235 | +
|
| 236 | +- case: typeclass_concrete_generic_delegate_and_tuple2 |
| 237 | + disable_cache: false |
| 238 | + main: | |
| 239 | + from typing import Tuple |
| 240 | + from classes import typeclass |
| 241 | +
|
| 242 | + class UserTupleMeta(type): |
| 243 | + def __instancecheck__(cls, arg: object) -> bool: |
| 244 | + try: |
| 245 | + return ( |
| 246 | + isinstance(arg, tuple) and |
| 247 | + isinstance(arg[0], str) and |
| 248 | + isinstance(arg[1], bool) |
| 249 | + ) |
| 250 | + except IndexError: |
| 251 | + return False |
| 252 | +
|
| 253 | + class UserTuple(Tuple[str, bool], metaclass=UserTupleMeta): |
| 254 | + ... |
| 255 | +
|
| 256 | + @typeclass |
| 257 | + def get_name(instance) -> str: |
| 258 | + ... |
| 259 | +
|
| 260 | + @get_name.instance(delegate=UserTuple) |
| 261 | + def _get_name_user_dict(instance: UserTuple) -> str: |
| 262 | + return instance[0] |
| 263 | +
|
| 264 | +
|
| 265 | + a = UserTuple(('a', True)) |
| 266 | + get_name(a) |
| 267 | +
|
| 268 | + get_name(()) |
| 269 | + get_name(('a', 'b')) |
| 270 | + get_name(('a', True)) |
| 271 | + get_name(('a', 'b', 'c')) |
| 272 | + out: | |
| 273 | + main:30: error: Argument 1 to "get_name" has incompatible type "Tuple[]"; expected "UserTuple" |
| 274 | + main:31: error: Argument 1 to "get_name" has incompatible type "Tuple[str, str]"; expected "UserTuple" |
| 275 | + main:32: error: Argument 1 to "get_name" has incompatible type "Tuple[str, bool]"; expected "UserTuple" |
| 276 | + main:33: error: Argument 1 to "get_name" has incompatible type "Tuple[str, str, str]"; expected "UserTuple" |
0 commit comments