Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for Python does abstractmethod containing non-empty body violate intended virtual/abstract design pattern?

Current License: CC BY-SA 4.0

Post Revisions

5 events
when toggle format what by license comment
Jun 20, 2020 at 9:12 history edited Community Bot
Commonmark migration
May 2, 2020 at 20:15 comment added Booboo Even an abstract method has to have some body (we all need somebody). Generally, I would just use pass as the method body for an abstract method. There is no point in using raise NotImplementedError. because a class that inherits from an abstract base class that does not override the abstract method will throw an exception once you try to instantiate an object of that class, so you will never have a chance to attempt to call the abstract method.
May 2, 2020 at 20:08 comment added juanpa.arrivillaga Note, virtual methods as a distinct thing don't make sense in Python, because all methods are overridable/inheritable, because the runtime type of an object always determines what method is called, there are no static/compile-time types in Python to allow for non-virtual methods to begin with, so that isn't really a useful distinction or category.
May 2, 2020 at 20:01 comment added juanpa.arrivillaga to put it simply, Python != C# Note, in the C++ sense, all python methods are virtual. Not all terminologies perfectly align or are relevant across languages.
May 2, 2020 at 19:54 history asked Intrastellar Explorer CC BY-SA 4.0

AltStyle によって変換されたページ (->オリジナル) /