MCPcopy Create free account
hub / github.com/python/cpython / __new__

Method __new__

Lib/test/test_descr.py:571–587  ·  view source on GitHub ↗
(metaclass, name, bases, dict)

Source from the content-addressed store, hash-verified

569 # Automatically create property attributes when methods
570 # named _get_x and/or _set_x are found
571 def __new__(metaclass, name, bases, dict):
572 hits = {}
573 for key, val in dict.items():
574 if key.startswith("_get_"):
575 key = key[5:]
576 get, set = hits.get(key, (None, None))
577 get = val
578 hits[key] = get, set
579 elif key.startswith("_set_"):
580 key = key[5:]
581 get, set = hits.get(key, (None, None))
582 set = val
583 hits[key] = get, set
584 for key, (get, set) in hits.items():
585 dict[key] = property(get, set)
586 return super(autoproperty, metaclass).__new__(metaclass,
587 name, bases, dict)
588 class A(metaclass=autoproperty):
589 def _get_x(self):
590 return -self.__x

Callers

nothing calls this directly

Calls 6

propertyClass · 0.85
superClass · 0.85
itemsMethod · 0.45
startswithMethod · 0.45
getMethod · 0.45
__new__Method · 0.45

Tested by

no test coverage detected