Shantanu <hauntsani...@gmail.com> added the comment:
Sure, I put together a draft PR here: https://github.com/python/cpython/pull/22848 Tests pass cleanly, though timeit indicates callable is slower. I haven't added instancecheck, which we should consider doing, since `isinstance(x, callable)` would now return False, instead of raising TypeError. @serhiy I hack around that using `callable.__new__`, so `callable[[int], str]()` raises a TypeError in my draft PR. Note that `callable[[int], str](f)` would work the same as `callable(f)` does today (which from a typechecking perspective is similar to the fact that `list[int](("a", "b", "c"))` works). I agree that callable being a predicate means that there probably isn't an aesthetically pleasing way of doing this. @kj I'm a little out of my comfort zone, so please let me know if you see a better way of doing things :-) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42102> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com