This repository has been archived by the owner on Oct 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from jacebrowning/strict-option
Disable attribute inference by default
- Loading branch information
Showing
19 changed files
with
193 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
"""Base classes for mapping and conversion.""" | ||
|
||
from .container import Container | ||
from .converter import Converter | ||
from .mappable import Mappable | ||
from .convertible import Convertible | ||
from .converter import Converter, Container |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,51 @@ | ||
"""Base classes for converters.""" | ||
"""Converter classes.""" | ||
|
||
import abc | ||
from abc import ABCMeta, abstractclassmethod, abstractmethod | ||
|
||
from .. import common | ||
from . import Mappable | ||
|
||
|
||
log = common.logger(__name__) | ||
|
||
|
||
class Converter(metaclass=abc.ABCMeta): | ||
"""Base class for immutable attribute converters.""" | ||
class Converter(metaclass=ABCMeta): | ||
"""Base class for attribute converters.""" | ||
|
||
@abc.abstractclassmethod | ||
@abstractclassmethod | ||
def create_default(cls): | ||
"""Create a default value for an attribute.""" | ||
raise NotImplementedError(common.OVERRIDE_MESSAGE) | ||
|
||
@abc.abstractclassmethod | ||
@abstractclassmethod | ||
def to_value(cls, data): | ||
"""Convert loaded data to an attribute's value.""" | ||
raise NotImplementedError(common.OVERRIDE_MESSAGE) | ||
|
||
@abc.abstractclassmethod | ||
@abstractclassmethod | ||
def to_data(cls, value): | ||
"""Convert an attribute to data optimized for dumping.""" | ||
raise NotImplementedError(common.OVERRIDE_MESSAGE) | ||
|
||
|
||
class Container(Mappable, Converter, metaclass=ABCMeta): | ||
"""Base class for mutable attribute converters.""" | ||
|
||
@classmethod | ||
def create_default(cls): | ||
return cls.__new__(cls) | ||
|
||
@classmethod | ||
def to_value(cls, data): | ||
value = cls.create_default() | ||
value.update_value(data, strict=False) | ||
return value | ||
|
||
@abstractmethod | ||
def update_value(self, data, strict): # pragma: no cover (abstract method) | ||
"""Update the attribute's value from loaded data.""" | ||
raise NotImplementedError(common.OVERRIDE_MESSAGE) | ||
|
||
def format_data(self): | ||
"""Format the attribute to data optimized for dumping.""" | ||
return self.to_data(self) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.