File: modify_dict_attr.py

package info (click to toggle)
python2.5 2.5-5
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 52,392 kB
  • ctags: 96,908
  • sloc: ansic: 352,790; python: 317,047; sh: 16,886; asm: 6,564; makefile: 4,292; lisp: 3,678; perl: 3,674; xml: 894; objc: 756; sed: 2
file content (19 lines) | stat: -rw-r--r-- 457 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# http://python.org/sf/1303614

class Y(object):
    pass

class type_with_modifiable_dict(Y, type):
    pass

class MyClass(object):
    """This class has its __dict__ attribute completely exposed:
    user code can read, reassign and even delete it.
    """
    __metaclass__ = type_with_modifiable_dict


if __name__ == '__main__':
    del MyClass.__dict__  # if we set tp_dict to NULL,
    print MyClass         # doing anything with MyClass segfaults