You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Note how this is different from `type[…]` which includes subclasses:
404
406
s1: type[Base] = Base
405
407
s2: type[Base] = Derived # no error here
406
408
407
-
# error: "Special form `ty_extensions.TypeOf` expected exactly one type parameter"
409
+
# error: "Special form `ty_extensions.TypeOf` expected exactly 1 type argument, got 3"
408
410
t: TypeOf[int, str, bytes]
409
411
410
412
# error: [invalid-type-form] "`ty_extensions.TypeOf` requires exactly one argument when used in a type expression"
@@ -414,8 +416,6 @@ def f(x: TypeOf) -> None:
414
416
415
417
## `CallableTypeOf`
416
418
417
-
<!-- pull-types:skip -->
418
-
419
419
The `CallableTypeOf` special form can be used to extract the `Callable` structural type inhabited by
420
420
a given callable object. This can be used to get the externally visibly signature of the object,
421
421
which can then be used to test various type properties.
@@ -434,15 +434,23 @@ def f2() -> int:
434
434
deff3(x: int, y: str) -> None:
435
435
return
436
436
437
-
# error: [invalid-type-form] "Special form `ty_extensions.CallableTypeOf` expected exactly one type parameter"
437
+
# error: [invalid-type-form] "Special form `ty_extensions.CallableTypeOf` expected exactly 1 type argument, got 2"
438
438
c1: CallableTypeOf[f1, f2]
439
439
440
440
# error: [invalid-type-form] "Expected the first argument to `ty_extensions.CallableTypeOf` to be a callable object, but got an object of type `Literal["foo"]`"
441
441
c2: CallableTypeOf["foo"]
442
442
443
+
# error: [invalid-type-form] "Expected the first argument to `ty_extensions.CallableTypeOf` to be a callable object, but got an object of type `Literal["foo"]`"
444
+
c20: CallableTypeOf[("foo",)]
445
+
443
446
# error: [invalid-type-form] "`ty_extensions.CallableTypeOf` requires exactly one argument when used in a type expression"
444
447
deff(x: CallableTypeOf) -> None:
445
448
reveal_type(x) # revealed: Unknown
449
+
450
+
c3: CallableTypeOf[(f3,)]
451
+
452
+
# error: [invalid-type-form] "Special form `ty_extensions.CallableTypeOf` expected exactly 1 type argument, got 0"
453
+
c4: CallableTypeOf[()]
446
454
```
447
455
448
456
Using it in annotation to reveal the signature of the callable object:
0 commit comments