Skip to content

Commit

Permalink
Merge pull request #354 from nickgaya/model-class-improvements
Browse files Browse the repository at this point in the history
Model class improvements
  • Loading branch information
sjaensch authored Oct 22, 2019
2 parents b78a6e3 + 0e305cd commit d92cab7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions bravado_core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from copy import deepcopy
from warnings import warn

import typing
from six import add_metaclass
from six import iteritems
from six import string_types
Expand All @@ -21,6 +22,10 @@
from bravado_core.util import ObjectType
from bravado_core.util import strip_xscope

if getattr(typing, 'TYPE_CHECKING', False):
from bravado_core._compat_typing import JSONDict
from bravado_core.spec import Spec

log = logging.getLogger(__name__)

# Models in #/definitions are tagged with this key so that they can be
Expand Down Expand Up @@ -302,6 +307,11 @@ class Model(object):
Class attribute that must be assigned on subclasses.
JSON-like dict that describes the model.
.. attribute:: _json_reference
Class attribute that must be assigned on subclasses.
JSON Uri where model spec could be found
.. attribute:: _properties
Class attribute that must be assigned on subclasses.
Expand All @@ -325,12 +335,13 @@ class Model(object):

# Use slots to reduce memory footprint of the Model instance
__slots__ = (
'_json_reference',
'_swagger_spec',
'_model_spec',
'_Model__dict', # Note the name mangling!
)

_swagger_spec = None # type: Spec
_model_spec = None # type: JSONDict
_json_reference = None # type: str

def __init__(self, **kwargs):
"""Initialize from property values in keyword arguments.
Expand Down Expand Up @@ -645,6 +656,7 @@ def create_model_type(swagger_spec, model_name, model_spec, bases=(Model,), json

return type(
str(model_name), bases, dict(
__slots__=(), # More memory-efficient
__doc__=ModelDocstring(),
_swagger_spec=swagger_spec,
_model_spec=model_spec,
Expand Down

0 comments on commit d92cab7

Please sign in to comment.