Skip to content

Commit 4a4d8ef

Browse files
committed
Revert "Fix #597: Implement ordered option inheritance without breaking the API of 2.x-line"
This reverts commit 25c1a1e.
1 parent b8e9b1a commit 4a4d8ef

2 files changed

Lines changed: 4 additions & 21 deletions

File tree

marshmallow/schema.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ def __new__(mcs, name, bases, attrs):
100100
meta = getattr(klass, 'Meta')
101101
# Set klass.opts in __new__ rather than __init__ so that it is accessible in
102102
# get_declared_fields
103-
klass.opts = klass.OPTIONS_CLASS(meta)
104-
# Pass the inherited `ordered` into opts
105-
klass.opts.ordered = ordered
103+
klass.opts = klass.OPTIONS_CLASS(meta, ordered=ordered)
106104
# Add fields specifid in the `include` class Meta option
107105
cls_fields += list(klass.opts.include.items())
108106

@@ -179,7 +177,7 @@ def _resolve_processors(self):
179177
class SchemaOpts(object):
180178
"""class Meta options for the :class:`Schema`. Defines defaults."""
181179

182-
def __init__(self, meta):
180+
def __init__(self, meta, ordered=False):
183181
self.fields = getattr(meta, 'fields', ())
184182
if not isinstance(self.fields, (list, tuple)):
185183
raise ValueError("`fields` option must be a list or tuple.")
@@ -201,7 +199,7 @@ def __init__(self, meta):
201199
'Schema.dump will be excluded from the serialized output by default.',
202200
UserWarning
203201
)
204-
self.ordered = getattr(meta, 'ordered', False)
202+
self.ordered = getattr(meta, 'ordered', ordered)
205203
self.index_errors = getattr(meta, 'index_errors', True)
206204
self.include = getattr(meta, 'include', {})
207205
self.load_only = getattr(meta, 'load_only', ())

tests/test_options.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from marshmallow import fields, Schema, SchemaOpts
6+
from marshmallow import fields, Schema
77
from marshmallow.exceptions import ValidationError
88

99
from tests.base import * # noqa
@@ -228,18 +228,3 @@ class AddFieldsChild(self.AddFieldsSchema):
228228
assert 'email' in s._declared_fields.keys()
229229
assert 'from' in s._declared_fields.keys()
230230
assert isinstance(s._declared_fields['from'], fields.Str)
231-
232-
233-
class CustomSchemaOpts(SchemaOpts):
234-
def __init__(self, meta):
235-
super(CustomSchemaOpts, self).__init__(meta)
236-
self.custom_option = True
237-
238-
class SchemaWithCustomSchemaOpts(Schema):
239-
OPTIONS_CLASS = CustomSchemaOpts
240-
241-
class TestSchemaOptsClass:
242-
243-
def test_schema_with_custom_schema_opts(self):
244-
s = SchemaWithCustomSchemaOpts()
245-
assert s.opts.custom_option

0 commit comments

Comments
 (0)