[issue42102] Make builtins.callable "generic"

2020-11-23 Thread Guido van Rossum
Guido van Rossum added the comment: No, they both have a different meaning. Object has (almost) no attributes. Any has all attributes. -- ___ Python tracker ___

[issue42102] Make builtins.callable "generic"

2020-11-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Could not object replace Any? -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue42102] Make builtins.callable "generic"

2020-11-22 Thread Guido van Rossum
Guido van Rossum added the comment: Hm. Shantanu's list shows that the next thing we should make usable without importing typing is Any. (I haven't any idea how to do that other than just making it a builtin.) But after that we should definitely tackle Callable, and the obvious way to do it

[issue42102] Make builtins.callable "generic"

2020-11-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: We specially introduced __mro_entries__ to make types in the typing module not classes. Turning builtins.callable into a class is a step back. -- ___ Python tracker

[issue42102] Make builtins.callable "generic"

2020-11-16 Thread Shantanu
Shantanu added the comment: My implementation in PR 22848 turns callable into a type and uses `__new__`. It isn't too bad. It does appear to affect performance of callable though. Here's some data on how often typing imports are used. This is the number of files in which `from typing import

[issue42102] Make builtins.callable "generic"

2020-11-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: >From implementation perspective it is not easy at all. You will need to create >a special class with methods __call__ and __getitem__ (and several other >methods and attributes, like __repr__, __reduce__, __name__, __doc__, >__module__,

[issue42102] Make builtins.callable "generic"

2020-11-16 Thread Guido van Rossum
Guido van Rossum added the comment: Well, it's certainly no bug fix, but just as PEP 585 lets us write list[int] instead of typing.List[int], it could be considered useful to be able to write callable[[int, int], str] instead of typing.Callable[[int, int], str]. It's easy enough to make it

[issue42102] Make builtins.callable "generic"

2020-11-16 Thread Batuhan Taskaya
Batuhan Taskaya added the comment: > Sorry, but making builtins.callable generic looks wrong to me. It is a > predicate, not a constructor. If it would be called "iscallable" instead of > "callable" nobody would propose to make it generic, right? It's just a > coincidence that the name of

[issue42102] Make builtins.callable "generic"

2020-11-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Sorry, but making builtins.callable generic looks wrong to me. It is a predicate, not a constructor. If it would be called "iscallable" instead of "callable" nobody would propose to make it generic, right? It's just a coincidence that the name of this

[issue42102] Make builtins.callable "generic"

2020-11-15 Thread Guido van Rossum
Guido van Rossum added the comment: I'd like to pursue this for real; other issues for callable have popped up, https://bugs.python.org/issue42195 and https://bugs.python.org/issue40494 (https://bugs.python.org/issue40398 is also related but already fixed). >From 42195 I learn that __args__

[issue42102] Make builtins.callable "generic"

2020-10-21 Thread Shantanu
Shantanu 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

[issue42102] Make builtins.callable "generic"

2020-10-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Callable is very special generic. It differs in many ways from List or Awaitable. You cannot just use GenericAlias. Also, in contrary to list() or dict(), callable() is not a constructor, it is a predicate. callable[[int], str]() does not make sense.

[issue42102] Make builtins.callable "generic"

2020-10-21 Thread Shantanu
Change by Shantanu : -- keywords: +patch pull_requests: +21796 stage: -> patch review pull_request: https://github.com/python/cpython/pull/22848 ___ Python tracker ___

[issue42102] Make builtins.callable "generic"

2020-10-20 Thread Guido van Rossum
Guido van Rossum added the comment: I'm not against this, though I'm not sure it really buys us much (Any still has to be imported from typing). Maybe you can submit a PR? Running the tests might be informative. -- ___ Python tracker

[issue42102] Make builtins.callable "generic"

2020-10-20 Thread Ken Jin
Ken Jin added the comment: +1 to this. I'm more surprised that callable wasn't already able to do that (also surprised at the ``isinstance(x, callable)`` code crashing). I think the implementation would be slightly different than what you proposed. I'd like to give it a shot if you aren't

[issue42102] Make builtins.callable "generic"

2020-10-20 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +gvanrossum, levkivskyi ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue42102] Make builtins.callable "generic"

2020-10-20 Thread Shantanu
New submission from Shantanu : In the post PEP 585 world, it seems like a bit of a stumbling block for builtins.callable to not able to be parametrised (in a runtime context). Post PEP 604, I'd expect typing.Callable to be the most used typing import after typing.Any, so much of PEP 585's