MCPcopy Index your code
hub / github.com/RustPython/RustPython / sort_attributes

Function sort_attributes

Lib/pydoc.py:365–375  ·  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

363 return results
364
365def sort_attributes(attrs, object):
366 'Sort the attrs list in-place by _fields and then alphabetically by name'
367 # This allows data descriptors to be ordered according
368 # to a _fields attribute if present.
369 fields = getattr(object, '_fields', [])
370 try:
371 field_order = {name : i-len(fields) for (i, name) in enumerate(fields)}
372 except TypeError:
373 field_order = {}
374 keyfunc = lambda attr: (field_order.get(attr[0], 0), attr[0])
375 attrs.sort(key=keyfunc)
376
377# ----------------------------------------------------- module manipulation
378

Callers 2

docclassMethod · 0.85
docclassMethod · 0.85

Calls 5

getattrFunction · 0.85
lenFunction · 0.85
enumerateFunction · 0.85
getMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected