MCPcopy
hub / github.com/python-attrs/attrs / _make_attr_tuple_class

Function _make_attr_tuple_class

src/attr/_make.py:265–283  ·  view source on GitHub ↗

Create a tuple subclass to hold `Attribute`s for an `attrs` class. The subclass is a bare tuple with properties for names. class MyClassAttributes(tuple): __slots__ = () x = property(itemgetter(0))

(cls_name: str, attr_names: list[str])

Source from the content-addressed store, hash-verified

263
264
265def _make_attr_tuple_class(cls_name: str, attr_names: list[str]) -> type:
266 """
267 Create a tuple subclass to hold `Attribute`s for an `attrs` class.
268
269 The subclass is a bare tuple with properties for names.
270
271 class MyClassAttributes(tuple):
272 __slots__ = ()
273 x = property(itemgetter(0))
274 """
275 attr_class_name = f"{cls_name}Attributes"
276 body = {}
277 for i, attr_name in enumerate(attr_names):
278
279 def getter(self, i=i):
280 return self[i]
281
282 body[attr_name] = property(getter)
283 return type(attr_class_name, (tuple,), body)
284
285
286# Tuple class for extracted attributes from a class definition.

Callers 1

_transform_attrsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected