MCPcopy Index your code
hub / github.com/python/cpython / sort_attributes

Function sort_attributes

Lib/pydoc.py:300–310  ·  view source on GitHub ↗

Sort the attrs list in-place by _fields and then alphabetically by name

(attrs, object)

Source from the content-addressed store, hash-verified

298 return results
299
300def sort_attributes(attrs, object):
301 'Sort the attrs list in-place by _fields and then alphabetically by name'
302 # This allows data descriptors to be ordered according
303 # to a _fields attribute if present.
304 fields = getattr(object, '_fields', [])
305 try:
306 field_order = {name : i-len(fields) for (i, name) in enumerate(fields)}
307 except TypeError:
308 field_order = {}
309 keyfunc = lambda attr: (field_order.get(attr[0], 0), attr[0])
310 attrs.sort(key=keyfunc)
311
312# ----------------------------------------------------- module manipulation
313

Callers 2

docclassMethod · 0.85
docclassMethod · 0.85

Calls 3

enumerateFunction · 0.85
getMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…