Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
Description
qpid.packer.Packer implements abstract methods incorrectly. Specifically, it uses the method suggested here. When an abstract method is called, the invalid name abstract results in a NameError exception. The merits of this approach, along with the other most common approaches, are summarized in the table below
Method | Stops Execution | Stops Execution at Object Creation | Sensible Exception Name |
---|---|---|---|
abstract keyword | yes | no | no |
raise NotImplementedError | yes | no | yes |
Abstract Base Classes | yes | yes | yes |
Using abstract is not preferable because a NameError does not make immediately clear what is going on. Raising a NotImplementedError exception is a great alternative because the exception name is logical. However, even better is the use of Abstract Base Classes (ABCs). ABCs raise an exception at object instantiation, whereas the other two methods do not result in an exception until an abstract method is called.
As an example, consider qpid.codec010.Codec. It is not immediately clear this class should not be used. And indeed, it is not used anywhere. Rather, qpid.codec010.StringCodec is the only class in qpid.codec010 meant to be used directly. Using an abstract base class prevents qpid.codec010.Codec objects from being created.
Attachments
Attachments
Issue Links
- split from
-
QPID-7070 qpid.messaging would become PEP8 compliant
- Resolved