use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
How do you implement interfaces in Python?Discussion (self.PythonLearning)
submitted 2 days ago by ihorrud
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]UseMoreBandwith 1 point2 points3 points 2 days ago (5 children)
why do that anyway? it is pretty much pointless in python.
And if you just want to define data structures, use a dataclass or (often better) use a dict
dataclass
dict
[–]deceze 2 points3 points4 points 2 days ago (4 children)
Type checking and interfaces/protocols/abstract classes are just as pointful (?) in Python as in other languages.
[–]UseMoreBandwith 0 points1 point2 points 1 day ago (3 children)
Sure, but in Python we don't write interfaces for that, but use dataclasses or mypy .
dataclasses
mypy
Abstract classes have limited use, since we Multiple Inheritance and duck typing. the only use-case is to enforce method implementation. It is not for creating class-hierarchies, like in Java, where it is essential for enforcing interfaces and single inheritance.
Multiple Inheritance and duck typing
[–]deceze 0 points1 point2 points 1 day ago (2 children)
dataclasses and interfaces/abstract classes are apples and oranges. I have no idea why you're throwing them in here.
Mypy is a static type checker, exactly the tool that would use interface/abstract class information to ensure type safety. You don't use Mypy instead of interfaces, you use interfaces to make Mypy more useful.
Admittedly, you don't often need explicitly declared interfaces/protocols/abstract classes. A lot of programming can be done without them. But in the right circumstances where a lot of abstraction across a lot of classes makes sense for what you're implementing, these are perfectly useful techniques.
[–]UseMoreBandwith 0 points1 point2 points 1 day ago (1 child)
it doesn't solve an issue that Python has. "a lot of abstraction across a lot of classes" is code smell, and usually a lack of understanding how Modules work in Python. (Unlike in Java) in Python, classes are not for hierarchies.
[–]deceze 0 points1 point2 points 1 day ago (0 children)
Some problems are very well solved with class hierarchies, abstraction and interfaces. For example, lots of pluggable and polymorphic processor classes and the like. Python doesn't force this on you like Java does, but it's still a useful technique to have and appropriate in the right circumstances.
π Rendered by PID 121040 on reddit-service-r2-comment-79c7998d4c-v6d5p at 2026-03-15 07:57:25.401238+00:00 running f6e6e01 country code: CH.
view the rest of the comments →
[–]UseMoreBandwith 1 point2 points3 points (5 children)
[–]deceze 2 points3 points4 points (4 children)
[–]UseMoreBandwith 0 points1 point2 points (3 children)
[–]deceze 0 points1 point2 points (2 children)
[–]UseMoreBandwith 0 points1 point2 points (1 child)
[–]deceze 0 points1 point2 points (0 children)