mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-08 23:50:38 +03:00
Improved Options merge attrs. Fixed #432
This commit is contained in:
parent
d5960a7630
commit
48efec307c
|
@ -20,8 +20,8 @@ class SpecialObjectTypeMeta(ObjectTypeMeta):
|
||||||
other_attr='default',
|
other_attr='default',
|
||||||
)
|
)
|
||||||
|
|
||||||
return ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options))
|
cls = ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options))
|
||||||
|
assert cls._meta is options
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,15 +20,21 @@ class ObjectTypeMeta(AbstractTypeMeta):
|
||||||
return type.__new__(cls, name, bases, attrs)
|
return type.__new__(cls, name, bases, attrs)
|
||||||
|
|
||||||
_meta = attrs.pop('_meta', None)
|
_meta = attrs.pop('_meta', None)
|
||||||
options = Options(
|
defaults = dict(
|
||||||
attrs.pop('Meta', None),
|
|
||||||
name=name,
|
name=name,
|
||||||
description=trim_docstring(attrs.get('__doc__')),
|
description=trim_docstring(attrs.get('__doc__')),
|
||||||
interfaces=(),
|
interfaces=(),
|
||||||
default_resolver=None,
|
default_resolver=None,
|
||||||
local_fields=OrderedDict(),
|
local_fields=OrderedDict(),
|
||||||
)
|
)
|
||||||
options.extend_with_meta(_meta)
|
if not _meta:
|
||||||
|
options = Options(
|
||||||
|
attrs.pop('Meta', None),
|
||||||
|
**defaults
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
options = _meta.extend_with_defaults(defaults)
|
||||||
|
|
||||||
options.base_fields = get_base_fields(bases, _as=Field)
|
options.base_fields = get_base_fields(bases, _as=Field)
|
||||||
|
|
||||||
if not options.local_fields:
|
if not options.local_fields:
|
||||||
|
|
|
@ -30,12 +30,11 @@ class Options(object):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def extend_with_meta(self, meta):
|
def extend_with_defaults(self, defaults):
|
||||||
if not meta:
|
for attr_name, value in defaults.items():
|
||||||
return
|
if not hasattr(self, attr_name):
|
||||||
meta_attrs = props(meta)
|
|
||||||
for attr_name, value in meta_attrs.items():
|
|
||||||
setattr(self, attr_name, value)
|
setattr(self, attr_name, value)
|
||||||
|
return self
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
options_props = props(self)
|
options_props = props(self)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user