(original) (raw)
On Sun, May 17, 2015 at 3:07 PM, Alex Grönholm <alex.gronholm@nextday.fi> wrote:
-- Looking at PEP 484, I came up with two use cases that I felt were not catered for:
- Specifying that a parameter should be a subclass of another (example: Type\[dict\] would match dict or OrderedDict; plain "Type" would equal "type" from builtins)
I don't understand. What is "Type"? Can you work this out in a full example? This code is already okay:
def foo(a: dict):
...
...
foo(OrderedDict())
- Specifying that a callable should take at least the specified arguments but would not be limited to them: Callable\[\[str, int, ...\], Any\]
Case #2 works already (Callable\[\[str, int\], Any\] if the unspecified arguments are optional, but not if they're mandatory. Any thoughts?
For #2 we explicitly debated this and found that there aren't use cases known that are strong enough to need additional flexibility in the args of a callable. (How is the code calling the callable going to know what arguments are safe to pass?) If there really is a need we can address in a future revision.
--Guido van Rossum (python.org/\~guido)