Ignore:
Timestamp:
12/08/06 10:36:53 (7 years ago)
Author:
xi
Message:

Use the types module instead of constructing type objects by hand. Fix #41. Thanks to v.haisman@… for the patch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/representer.py

    r225 r235  
    1313    from sets import Set as set 
    1414 
    15 import sys, copy_reg 
     15import sys, copy_reg, types 
    1616 
    1717class RepresenterError(YAMLError): 
     
    3636        self.object_keeper = [] 
    3737        self.alias_key = None 
    38  
    39     class C: pass 
    40     c = C() 
    41     def f(): pass 
    42     def g(): yield None 
    43     classobj_type = type(C) 
    44     instance_type = type(c) 
    45     function_type = type(f) 
    46     generator_type = type(g()) 
    47     builtin_function_type = type(abs) 
    48     module_type = type(sys) 
    49     del C, c, f, g 
    5038 
    5139    def get_classobj_bases(self, cls): 
     
    6957            self.object_keeper.append(data) 
    7058        data_types = type(data).__mro__ 
    71         if type(data) is self.instance_type: 
     59        if type(data) is types.InstanceType: 
    7260            data_types = self.get_classobj_bases(data.__class__)+list(data_types) 
    7361        if data_types[0] in self.yaml_representers: 
     
    472460        Representer.represent_name) 
    473461 
    474 Representer.add_representer(Representer.classobj_type, 
     462Representer.add_representer(types.ClassType, 
    475463        Representer.represent_name) 
    476464 
    477 Representer.add_representer(Representer.function_type, 
     465Representer.add_representer(types.FunctionType, 
    478466        Representer.represent_name) 
    479467 
    480 Representer.add_representer(Representer.builtin_function_type, 
     468Representer.add_representer(types.BuiltinFunctionType, 
    481469        Representer.represent_name) 
    482470 
    483 Representer.add_representer(Representer.module_type, 
     471Representer.add_representer(types.ModuleType, 
    484472        Representer.represent_module) 
    485473 
    486 Representer.add_multi_representer(Representer.instance_type, 
     474Representer.add_multi_representer(types.InstanceType, 
    487475        Representer.represent_instance) 
    488476 
Note: See TracChangeset for help on using the changeset viewer.