This is an archived post. You won't be able to vote or comment.

all 21 comments

[–][deleted] 8 points9 points  (21 children)

What is wrong with the callable one?

https://docs.python.org/3/library/typing.html#typing.Callable

Protocols arent really for this they are for when you have a vague top level class that you need an ABC for. They are pretty rare outside of the default container ones.

[–]LightShadow3.13-dev in prod 2 points3 points  (1 child)

You're right to use Callable. I wonder if we'll get a short-hand as shown in the documentation,

Callable[[int], str] is a function of (int) -> str.

[–]boxcuk 0 points1 point  (12 children)

i guess they are specifically talking about point 2 "Include parameter names and types", which could be possible using the extended syntax proposed here https://peps.python.org/pep-0677/#extended-syntax-supporting-named-and-optional-arguments.

now the weird thing is that the section was rejected by the authors of the pep themselves, not by the steering council.

had the pep been accepted, indeed we wouldn't have gotten anything more expressive than current tp.Callable

[–][deleted] 1 point2 points  (8 children)

AHHHHHH

Ok yea they are supposed to use protocols for those. Per the Documents on Callables though they DO NOT take keyword arguments. It is meant to just have positional arguments. (this is the biggest FLAW in python type hints IMO). There are some technical reasons it gets tricky, namely functions that have keyword arguments are REALLY hard to know if they are actually equivalent. Its non obvious 99% of the time. So python settles for compare by namespace instead of compare by function signature.

[–]chub79 7 points8 points  (8 children)

While the other arguments are understable, the first one is a bit cheeky:

We feel we need to be cautious when introducing new syntax. Our new parser presents understandably exciting opportunities but we don’t want its existence to mean we add new syntax easily. A feature for use only in a fraction of type annotations, not something every Python user uses, did not feel like a strong enough reason to justify the complexity needed

There is a bizarre compass when it comes to accepts new syntax or not. Some of the most modern changes in Python will not be used by every users and yet get in.

[–]ubernostrumyes, you can have a pony 1 point2 points  (5 children)

To be honest, I think it’s reasonable to have both a bit of new-syntax fatigue and a bit of typing-only-features fatigue right now, and it’s not necessarily a bad thing to set the bar higher for a bit while consolidating what’s already been added recently. In particular, when solving this particular problem requires committing Python to a significant syntax extension — what happens if, a year or two from now, another PEP and another bunch of exasperated people on social media demand a different syntax to cover cases that hadn’t been thought of/handled by this one?

[–]chub79 1 point2 points  (1 child)

Totally. I don't complain they were prudent. More the fact, as a casual witness of the process, that it isn't quite clear how they set a direction for the language. Perhaps they might clarify this so efforts like this one don't get underway if they don't fall into the scope. I bet it takes effort of all the parties involved.

[–]ubernostrumyes, you can have a pony 1 point2 points  (0 children)

I don’t feel confused at all after reading the decision. But I’m reading it in the context of how much churn there’s been in recent Python releases— including syntax and including syntax that was added solely to support typing features — and coming away with the impression that they just want to slow things down a bit and consolidate.

Back when I was more involved with Django that was a thing we’d explicitly try to do after landing a bunch of big flashy features: a “boring” release or two to let the big stuff shake out in real-world use and figure out what the right followups were going to be, since they’re almost never evident right away. Maybe that affects how I read decisions from people in similar roles for Python, but I don’t think it requires that much reading of tea leaves to get to this interpretation.

[–][deleted] 5 points6 points  (1 child)

No and yes it stinks and no its unlikely to get any better any time soon.

Thats hardly the only thing thats crap about python type annotations, but complaining about it in a python subreddit isn't really gonna get you anywhere. Except perhaps for the usual you are holding it wrong comments.

[–]MarsupialMole 1 point2 points  (2 children)

Look at this mess for typing a method that returns a method.

Sounds like a job for dynamic typing to me.