Skip to content

Protocol should be documented as using ABCMeta as metaclass #127677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
srittau opened this issue Dec 6, 2024 · 1 comment
Open

Protocol should be documented as using ABCMeta as metaclass #127677

srittau opened this issue Dec 6, 2024 · 1 comment
Labels
docs Documentation in the Doc dir topic-typing

Comments

@srittau
Copy link
Contributor

srittau commented Dec 6, 2024

Documentation

Came up in #127648.

Currently the documentation for typing.Protocol doesn't mention that Protocol has ABCMeta in its metaclasses (indirectly via _ProtocolMeta) and that its methods can (should?) be marked with @abstractmethod. In fact, neither the string "ABCMeta" nor "abstractmethod" appear in the documentation for the typing module.

I also suggest to add @abstractmethod to the examples using a Protocol as that is probably a best practice.

Finally, the documentation for Protocol suggests to see PEP 544 for more details. I don't think this is particularly helpful. All information relevant for users should be in the main documentation. PEP 544 should only be suggested as a historical document. (And I don't suggest to directly link to the typing spec, either, although a general link at the top of the page would be useful.)

@srittau srittau added the docs Documentation in the Doc dir label Dec 6, 2024
@JelleZijlstra
Copy link
Member

I also suggest to add @AbstractMethod to the examples using a Protocol as that is probably a best practice.

Not sure how I feel about this. There is some benefit, but it doesn't feel great to make protocol definitions even more verbose. Plus, Protocol is meant to be used with static type checkers, which can already figure out when a method definition is abstract.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir topic-typing
Projects
Status: Todo
Development

No branches or pull requests

3 participants