Bit of style fudging

This commit is contained in:
Hynek Schlawack 2018-01-29 07:40:36 +01:00
parent b47c6ce8b1
commit f80cabadf9
1 changed files with 14 additions and 11 deletions

View File

@ -201,9 +201,9 @@ def _make_attr_tuple_class(cls_name, attr_names):
# Tuple class for extracted attributes from a class definition. # Tuple class for extracted attributes from a class definition.
# `super_attrs` is a subset of `attrs`. # `super_attrs` is a subset of `attrs`.
_Attributes = _make_attr_tuple_class("_Attributes", [ _Attributes = _make_attr_tuple_class("_Attributes", [
"attrs", # all attributes to build dunder methods for "attrs", # all attributes to build dunder methods for
"super_attrs", # attributes that have been inherited from super classes "super_attrs", # attributes that have been inherited
"super_attrs_map", # map super attributes to their originating classes "super_attrs_map", # map inherited attributes to their originating classes
]) ])
@ -371,8 +371,9 @@ class _ClassBuilder(object):
) )
def __init__(self, cls, these, slots, frozen, auto_attribs): def __init__(self, cls, these, slots, frozen, auto_attribs):
attrs, super_attrs, super_map = _transform_attrs(cls, these, attrs, super_attrs, super_map = _transform_attrs(
auto_attribs) cls, these, auto_attribs
)
self._cls = cls self._cls = cls
self._cls_dict = dict(cls.__dict__) if slots else {} self._cls_dict = dict(cls.__dict__) if slots else {}
@ -1015,7 +1016,7 @@ def _add_init(cls, frozen):
cls.__attrs_attrs__, cls.__attrs_attrs__,
getattr(cls, "__attrs_post_init__", False), getattr(cls, "__attrs_post_init__", False),
frozen, frozen,
'__slots__' in cls.__dict__, _is_slot_cls(cls),
{}, {},
) )
return cls return cls
@ -1066,15 +1067,15 @@ def validate(inst):
v(inst, a, getattr(inst, a.name)) v(inst, a, getattr(inst, a.name))
def _is_slot_cl(cl): def _is_slot_cls(cls):
return '__slots__' in cl.__dict__ return "__slots__" in cls.__dict__
def _is_slot_attr(a_name, super_attr_map): def _is_slot_attr(a_name, super_attr_map):
""" """
Check if the attribute name comes from a slot class. Check if the attribute name comes from a slot class.
""" """
return a_name in super_attr_map and _is_slot_cl(super_attr_map[a_name]) return a_name in super_attr_map and _is_slot_cls(super_attr_map[a_name])
def _attrs_to_init_script(attrs, frozen, slots, post_init, super_attr_map): def _attrs_to_init_script(attrs, frozen, slots, post_init, super_attr_map):
@ -1087,8 +1088,10 @@ def _attrs_to_init_script(attrs, frozen, slots, post_init, super_attr_map):
a cached ``object.__setattr__``. a cached ``object.__setattr__``.
""" """
lines = [] lines = []
any_slot_ancestors = any(_is_slot_attr(a.name, super_attr_map) any_slot_ancestors = any(
for a in attrs) _is_slot_attr(a.name, super_attr_map)
for a in attrs
)
if frozen is True: if frozen is True:
if slots is True: if slots is True:
lines.append( lines.append(