python / typing-council

Decisions by the Python Typing Council
43 stars 3 forks source link

Typing spec update for callables #28

Closed erictraut closed 6 months ago

erictraut commented 6 months ago

I'd like to request that the TC consider adoption of a new chapter in the typing spec that fills in some missing information about callables, including rules for subtyping.

Links to PR & Discussion The PR can be found here. The latest draft incorporates feedback from PR reviews and the discussion.

The discussion can be found here.

TC Sign-off

Current Type Checker Behaviors Most of the update is simply documenting behaviors that type checkers exhibit today.

There is one aspect of the update that will require changes to all type checkers. It is related to the treatment of (*args: Any, **kwargs: Any) as the same as ... in a Callable annotation. The behavior in the draft specification is close to what mypy currently implements, but there are some differences that will require small changes in mypy. The other three major type checkers do not currently treat (*args: Any, **kwargs: Any) specially, so they will require updates to conform to the proposed spec.

Controversial Issues The only controversial issue relates to the special treatment of (*args: Any, **kwargs: Any). Some people (myself included) would prefer not to treat this specially, but taking into consideration mypy's historical behavior and the pain involved in changing it, a compromise makes sense here. It is not dissimilar to the decision we made for tuple[Any, ...].

rchen152 commented 6 months ago

I signed off. I'm not a huge fan of special-casing (*args: Any, **kwargs: Any), but it seems like a reasonable compromise.

gvanrossum commented 6 months ago

I sent a PR review with some optional editorial nits, and signed off. Glad to see this concluded!