Menu

#20 Use abstract classes

0.8
work-in-progress
all (7)
2017-08-08
2014-01-29
No

Note: it may be necessary to update the core classes for that.

All abstract classes should be "declared" as abstract.

So far, they just have methods that raise error.MethodShouldBeRedefined exceptions if they're used. This kind of Exception will become useless, hence remove them.

Classes that should become abstract are:

  • all *_Structure classes from machine/ and from sheet/ and its subdirectories
  • in the core:
  • Clonable, Named, Printable, ComposedCalculable, Evaluable, Calculable, Signed, Exponented, Operation, CommutativeOperation

Explanation / documentation:
http://dbader.org/blog/abstract-base-classes-in-python
http://docs.python.org/3.4/library/abc.html

Tests: maybe check that instanciation any of these classes raises a TypeError (see tests/00_libs/test_startup_actions.py for an example how to test if an Exception is raised)

When this is done, there shouldn't be any "MethodShouldBeRedefined" throughout all code (if there are, I may have forgotten to list some classes). And as a side effect, the unit tests' coverage rate may increase a little bit (don't know if the pass statements in abstract methods are counted or not).

Discussion

  • Nicolas Hainaux

    Nicolas Hainaux - 2016-07-09
    • Milestone: 0.7.1 --> 1.0
     
  • Nicolas Hainaux

    Nicolas Hainaux - 2016-07-20
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -7,3 +7,5 @@
     * all *_Structure classes from machine/ and from sheet/ and its subdirectories
     * in the core:
     - Clonable, Named, Printable, ComposedCalculable, Evaluable, Calculable, Signed, Exponented, Operation, CommutativeOperation
    +
    +When this is done, there shouldn't be any "MethodShouldBeRedefined" throughout all code.
    
     
  • Nicolas Hainaux

    Nicolas Hainaux - 2016-07-20
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,6 @@
     All abstract classes should be "declared" as abstract.
    
    -So far, they just have methods that raise error.MethodShouldBeRedefined exceptions if they're used. This kind of Exception will become useless, hence remove them. As a side effect, the unit tests' coverage rate may increase significantly.
    +So far, they just have methods that raise error.MethodShouldBeRedefined exceptions if they're used. This kind of Exception will become useless, hence remove them.
    
     Classes that should become abstract are:
    
    @@ -8,4 +8,10 @@
     * in the core:
     - Clonable, Named, Printable, ComposedCalculable, Evaluable, Calculable, Signed, Exponented, Operation, CommutativeOperation
    
    -When this is done, there shouldn't be any "MethodShouldBeRedefined" throughout all code.
    +Documentation:
    +
    +
    +
    +Tests: maybe check that instanciating any of these classes raises a TypeError
    +
    +When this is done, there shouldn't be any "MethodShouldBeRedefined" throughout all code. And as a side effect, the unit tests' coverage rate may increase a little bit (don't know if the `pass` statements in abstract methods are counted or not).
    
     
  • Nicolas Hainaux

    Nicolas Hainaux - 2016-07-20
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -8,10 +8,10 @@
     * in the core:
     - Clonable, Named, Printable, ComposedCalculable, Evaluable, Calculable, Signed, Exponented, Operation, CommutativeOperation
    
    -Documentation:
    +Explanation / documentation:
    +http://dbader.org/blog/abstract-base-classes-in-python
    +http://docs.python.org/3.4/library/abc.html
    
    +Tests: maybe check that instanciation any of these classes raises a TypeError
    
    -
    -Tests: maybe check that instanciating any of these classes raises a TypeError
    -
    -When this is done, there shouldn't be any "MethodShouldBeRedefined" throughout all code. And as a side effect, the unit tests' coverage rate may increase a little bit (don't know if the `pass` statements in abstract methods are counted or not).
    +When this is done, there shouldn't be any "MethodShouldBeRedefined" throughout all code (if there are, I may have forgotten to list some classes). And as a side effect, the unit tests' coverage rate may increase a little bit (don't know if the `pass` statements in abstract methods are counted or not).
    
     
  • Nicolas Hainaux

    Nicolas Hainaux - 2016-07-20
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -12,6 +12,6 @@
     http://dbader.org/blog/abstract-base-classes-in-python
     http://docs.python.org/3.4/library/abc.html
    
    -Tests: maybe check that instanciation any of these classes raises a TypeError
    +Tests: maybe check that instanciation any of these classes raises a TypeError (see tests/00_libs/test_startup_actions.py for an example how to test if an Exception is raised)
    
     When this is done, there shouldn't be any "MethodShouldBeRedefined" throughout all code (if there are, I may have forgotten to list some classes). And as a side effect, the unit tests' coverage rate may increase a little bit (don't know if the `pass` statements in abstract methods are counted or not).
    
     
  • Nicolas Hainaux

    Nicolas Hainaux - 2017-08-04
    • assigned_to: Nicolas Hainaux
    • Milestone: 1.0 --> 0.7.1
     
  • Nicolas Hainaux

    Nicolas Hainaux - 2017-08-04
    • status: open --> work-in-progress
     
  • Nicolas Hainaux

    Nicolas Hainaux - 2017-08-08
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,3 +1,5 @@
    +Note: it may be necessary to update the core classes for that.
    +
     All abstract classes should be "declared" as abstract.
    
     So far, they just have methods that raise error.MethodShouldBeRedefined exceptions if they're used. This kind of Exception will become useless, hence remove them.
    
    • Milestone: 0.7.1 --> 0.8
     

Log in to post a comment.