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

Method verify_dict_readonly

Lib/test/test_descr.py:3526–3543  ·  view source on GitHub ↗

x has to be an instance of a class inheriting from Base.

(x)

Source from the content-addressed store, hash-verified

3524 class Base(object):
3525 pass
3526 def verify_dict_readonly(x):
3527 """
3528 x has to be an instance of a class inheriting from Base.
3529 """
3530 cant(x, {})
3531 try:
3532 del x.__dict__
3533 except (AttributeError, TypeError):
3534 pass
3535 else:
3536 self.fail("shouldn't allow del %r.__dict__" % x)
3537 dict_descr = Base.__dict__["__dict__"]
3538 try:
3539 dict_descr.__set__(x, {})
3540 except (AttributeError, TypeError):
3541 pass
3542 else:
3543 self.fail("dict_descr allowed access to %r's dict" % x)
3544
3545 # Classes don't allow __dict__ assignment and have readonly dicts
3546 class Meta1(type, Base):

Callers

nothing calls this directly

Calls 2

failMethod · 0.45
__set__Method · 0.45

Tested by

no test coverage detected