This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Feature Request for Python Interfaces
Type: enhancement Stage: resolved
Components: Versions: Python 3.11
process
Status: closed Resolution: later
Dependencies: Superseder:
Assigned To: Nosy List: Gobot1234, Orie, ronaldoussoren, terry.reedy
Priority: normal Keywords:

Created on 2021-12-24 16:17 by Orie, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg409149 - (view) Author: Or (Orie) Date: 2021-12-24 16:17
Most object oriented languages provide interfaces as part of the core language, this helps bring better design principles to a team's workflows.

Today Python provides the ABC module for abstract base classes and the Protocol class from typing module as something that might resemble an interface.

Creating abstract classes to simulate interface behavior is pretty tedious and the Protocol class is not supported by IDEs for type hints, completions, bug findings, etc.

I think the Python community would really benefit if we have an interface keyword built into the core language and enforced by the interpreter, similar to how it's implemented in Java and C#.
msg409153 - (view) Author: Gobot1234 (Gobot1234) * Date: 2021-12-24 18:26
> Protocol class is not supported by IDEs for type hints, completions, bug findings, etc.

I think most good modern IDEs support using Protocols as type hints, offer completions on them and help you to find bugs with static analysis. That was one of the main reasons they were implemented.
msg409165 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-12-25 02:02
(IDLE does not support typing.Protocol classes, because no one has proposed that it do so, let alone submit a patch.)

A new keyword requires a PEP that specifies the syntax for an 'interface' statement and what such a statement would do.  You should start with discussion on the python-ideas list.  This should probably be closed until there is a concrete proposal that could be evaluated and possibly implemented or rejected.
msg409180 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2021-12-26 09:23
I agree with Terry. This requires a clear proposal that describes the behaviour and differences with ABC-s.

I'm closing this issue for now.
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90332
2021-12-26 09:23:24ronaldoussorensetstatus: open -> closed

nosy: + ronaldoussoren
messages: + msg409180

resolution: later
stage: resolved
2021-12-25 02:02:53terry.reedysetnosy: + terry.reedy
messages: + msg409165
2021-12-24 18:26:29Gobot1234setnosy: + Gobot1234
messages: + msg409153
2021-12-24 16:17:33Oriecreate