Closed jolyonb closed 5 years ago
So, today I learnt something about metaclasses and abstract base classes in python. Metaclasses are inherited through subclassing, so we didn't need to import abc.ABCMeta
on subclasses that were abstract.
Furthermore, metaclass implementation changed between python 2 and 3, so we need to use six
to apply them.
Finally, the ABCMeta
metaclass only enforces that a class instance has no methods that are marked as abstract. In some sampling situations, we were marking things as abstract that had all of their methods in place, and the abstract marking was doing nothing.
Upshot of all this is that the only class that needs to be marked as abstract is ObjectWithSchema
, and everything else follows from there.
@ChristopherChudzicki This is ready for review. Warning: short, but a little involved.
Ok, looks like I broke it... Be right back!
Should be ready for final review now.
Merging #250 into master will not change coverage. The diff coverage is
100%
.
@@ Coverage Diff @@
## master #250 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 28 29 +1
Lines 2426 2452 +26
=====================================
+ Hits 2426 2452 +26
Pretty much what it says in the title.
This was a tricky little thing to get right, and involved my first ever use of my own metaclass. The basic idea is to have a
default_values
property associated with each class (not class instance, but class; hence the need for a metaclass). Then, right before schema validation, look up the classdefault_values
property, and all of the superclasses, to construct the complete configuration. I think the end result is really neat though, and provides a really easy way to set global defaults.Resolves #249.