Skip to content

Commit

Permalink
Field supports cooperative inheritance through **kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
numberoverzero committed Aug 7, 2015
1 parent 5523923 commit b7c9e1d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
11 changes: 0 additions & 11 deletions CHANGES.rst

This file was deleted.

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare 0.9.6
declare 0.9.7
========
:Build: |build|_ |coverage|_
:Documentation: http://declare.readthedocs.org/
Expand Down
9 changes: 5 additions & 4 deletions declare.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid
__all__ = ["ModelMetaclass", "Field", "TypeDefinition",
"TypeEngine", "DeclareException"]
__version__ = "0.9.6"
__version__ = "0.9.7"

missing = object()
# These engines can't be cleared
Expand Down Expand Up @@ -253,7 +253,7 @@ def __contains__(self, typedef):
_fixed_engines["global"] = TypeEngine("global")


class TypeDefinition(object):
class TypeDefinition:
'''
Translates between python types and backend/storage/transport types
Expand Down Expand Up @@ -347,8 +347,8 @@ def instanceof(obj, classinfo):
return False


class Field(object):
def __init__(self, typedef=None, **kwargs):
class Field:
def __init__(self, *, typedef=None, **kwargs):
self._model_name = None
if typedef is None:
self.typedef = typedef
Expand All @@ -361,6 +361,7 @@ def __init__(self, typedef=None, **kwargs):
raise TypeError(("Expected {} to be None, instance of "
"TypeDefinition, or subclass of"
"TypeDefinition".format(typedef)))
super().__init__(**kwargs)

@property
def model_name(self):
Expand Down
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
""" Setup file """
import os
import re
from setuptools import setup, find_packages

HERE = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(HERE, 'README.rst')).read()
CHANGES = open(os.path.join(HERE, 'CHANGES.rst')).read()
# Remove custom RST extensions for pypi
CHANGES = re.sub(r'\(\s*:(issue|pr|sha):.*?\)', '', CHANGES)


def get_version():
Expand All @@ -28,7 +24,7 @@ def get_version():
name='declare',
version=get_version(),
description="Declarative scaffolding for frameworks",
long_description=README + '\n\n' + CHANGES,
long_description=README,
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
Expand Down
15 changes: 15 additions & 0 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,18 @@ def test_wrong_typedef_type():

with pytest.raises(TypeError):
Field(typedef=int)


def test_cooperate_inheritance():

''' unused kwargs are delegated to other __init__ methods in the MRO '''
class OtherBase:
def __init__(self, *, foo, **kwargs):
self.foo = foo
super().__init__(**kwargs)

class Class(Field, OtherBase):
pass

obj = Class(typedef=TypeDefinition, foo='bar')
assert obj.foo == 'bar'

0 comments on commit b7c9e1d

Please sign in to comment.