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
Copy file name to clipboardexpand all lines: README.md
+14-4
Original file line number
Diff line number
Diff line change
@@ -100,16 +100,26 @@ for subclass in (float, list, list[float], tuple[int]):
100
100
assertnotissubclass(subclass, cls)
101
101
```
102
102
103
-
If a type implements a custom `__instancecheck__`, it can opt-in to dispatch (without caching) by registering its metaclass and bases with `subtype.origins`. `parametric` provides a convenient constructor, with support for predicate functions and checking attributes.
103
+
If a type implements a custom `__instancecheck__`, it can opt-in to dispatch (without caching) by registering its metaclass and bases with `subtype.origins`. `parametric` provides a convenient constructor, which will match the base class, predicate functions, and check attributes.
`overload` used to dispatch on annotated predicate functions. It is deprecated because a custom instance check - including using `parametric` - offers the same functionality.
112
+
`overload` used to dispatch on annotated predicate functions. It is deprecated because a custom instance check - including using `parametric` - offers the same functionality. Any predicate function can be wrapped with the closest matching base class, including `object` if necessary.
113
+
114
+
```python
115
+
Cls = parametric(object, predicate)
116
+
Digits = parametric(str, str.isdigit)
117
+
assertisinstance('0', Digits)
118
+
assertnotisinstance('a', Digits)
119
+
120
+
@meth.register
121
+
def_(arg: Digits): ...
122
+
```
113
123
114
124
### classes
115
125
`classmethod` and `staticmethod` may be used with a multimethod, but must be applied _last_, i.e., wrapping the final multimethod definition after all functions are registered. For class and instance methods, `cls` and `self` participate in the dispatch as usual. They may be left blank when using annotations, otherwise use `object` as a placeholder.
0 commit comments