Ejemplo n.º 1
0
 def replace_types( me, **newtypes):
     '''uses newtypes (as valuedefs) instead.
     warn: to make optional( bool) into explicit 3-state textual,
         do not use optional( bool, aliaser( True:t1,False:t2,else:t3))..
         needs optional( enum( t1:True,t2:False,t3:else))
     '''
     #assert not me.__dict__.get( '_methods_dict'), 'dont replace already used type, first inherit it'
     r = dictOrder()
     for w in me.methods_walk():
         w = DictAttr( w.__dict__)
         w.decl = w.decl.clone_new_types( types= newtypes)
         r[ w.name] = w
     me._methods_dict = r
Ejemplo n.º 2
0
    if 0: #cyk
        DictAttrTrans2 = make_dict_trans( DictAttr)
        e= DictAttrTrans2( a=2, _prevodach= dict( c='d') )
        tDictAttrTrans( e)

    #########

    txt = '''
        a = 4

        b = 5
        #c =6 7
        '''
    d = dictOrder_fromstr( txt, dict= dictOrder)
    assert d == dictOrder( [['a','4'], ['b','5']] ), d
    d = dictOrder_fromstr( txt, dict= dictOrder, ignore_comments =False)
    assert d == dictOrder( [['a','4'], ['b','5'], ['#c','6 7']] ), d

    dab = dict( a=1, b=2)
    dac = dict( a=3, c=2)

    assert subtract( dab, dac) == dict( b=2)
    assert remove( dab.copy(), dac) == dict( b=2)

    assert intersection( dab, dac) == dict( a=1)
    assert intersection( dac, dab) == dict( a=3)
    assert intersect_update( dab, dac) == dict( a=1)

# vim:ts=4:sw=4:expandtab
Ejemplo n.º 3
0
 def methods_dict( me, clear =False):
     r = not clear and me.__dict__.get( '_methods_dict') or None   #local klas attribute
     if r is None:
         me._methods_dict = r = dictOrder( (w.name, w)
                     for w in me._methods_walk( me, raw= True) )
     return r