@@ -149,8 +149,10 @@ def _get_builtin(*args):
149
149
return cls ._generated [args ]
150
150
return _get_builtin
151
151
152
+
152
153
def _create_builtin_getter (cls ):
153
154
type_getter = _create_builtin_type_getter (cls )
155
+
154
156
def _get_builtin (* args ):
155
157
return pyobjects .PyObject (type_getter (* args ))
156
158
return _get_builtin
@@ -233,7 +235,7 @@ def __call__(self, name, returned=None, function=None,
233
235
except AttributeError :
234
236
if check_existence :
235
237
raise
236
- builtin = None
238
+ builtin = None
237
239
self .attributes [name ] = BuiltinName (
238
240
BuiltinFunction (returned = returned , function = function ,
239
241
argnames = argnames , builtin = builtin ))
@@ -252,7 +254,8 @@ def __init__(self, holding=None):
252
254
collector ('__new__' , function = self ._new_list )
253
255
254
256
# Adding methods
255
- collector ('append' , function = self ._list_add , argnames = ['self' , 'value' ])
257
+ collector ('append' , function = self ._list_add ,
258
+ argnames = ['self' , 'value' ])
256
259
collector ('__setitem__' , function = self ._list_add ,
257
260
argnames = ['self' , 'index' , 'value' ])
258
261
collector ('insert' , function = self ._list_add ,
@@ -306,7 +309,6 @@ class Dict(BuiltinClass):
306
309
def __init__ (self , keys = None , values = None ):
307
310
self .keys = keys
308
311
self .values = values
309
- item = get_tuple (self .keys , self .values )
310
312
collector = _AttributeCollector (dict )
311
313
collector ('__new__' , function = self ._new_dict )
312
314
collector ('__setitem__' , function = self ._dict_add )
@@ -327,7 +329,8 @@ def do_create(holding=None):
327
329
if holding is None :
328
330
return get_dict ()
329
331
type = holding .get_type ()
330
- if isinstance (type , Tuple ) and len (type .get_holding_objects ()) == 2 :
332
+ if isinstance (type , Tuple ) and \
333
+ len (type .get_holding_objects ()) == 2 :
331
334
return get_dict (* type .get_holding_objects ())
332
335
return _create_builtin (args , do_create )
333
336
@@ -384,7 +387,7 @@ def _self_set(self, context):
384
387
if new_dict and isinstance (new_dict .get_object ().get_type (), Dict ):
385
388
args = arguments .ObjectArguments ([new_dict ])
386
389
items = new_dict .get_object ()['popitem' ].\
387
- get_object ().get_returned_object (args )
390
+ get_object ().get_returned_object (args )
388
391
context .save_per_name (items )
389
392
else :
390
393
holding = _infer_sequence_for_pyname (new_dict )
@@ -405,7 +408,8 @@ def __init__(self, *objects):
405
408
first = objects [0 ]
406
409
attributes = {
407
410
'__getitem__' : BuiltinName (BuiltinFunction (first )),
408
- '__getslice__' : BuiltinName (BuiltinFunction (pyobjects .PyObject (self ))),
411
+ '__getslice__' :
412
+ BuiltinName (BuiltinFunction (pyobjects .PyObject (self ))),
409
413
'__new__' : BuiltinName (BuiltinFunction (function = self ._new_tuple )),
410
414
'__iter__' : BuiltinName (BuiltinFunction (get_iterator (first )))}
411
415
super (Tuple , self ).__init__ (tuple , attributes )
@@ -485,8 +489,9 @@ def __init__(self):
485
489
486
490
self_methods = ['__getitem__' , '__getslice__' , 'capitalize' , 'center' ,
487
491
'decode' , 'encode' , 'expandtabs' , 'join' , 'ljust' ,
488
- 'lower' , 'lstrip' , 'replace' , 'rjust' , 'rstrip' , 'strip' ,
489
- 'swapcase' , 'title' , 'translate' , 'upper' , 'zfill' ]
492
+ 'lower' , 'lstrip' , 'replace' , 'rjust' , 'rstrip' ,
493
+ 'strip' , 'swapcase' , 'title' , 'translate' , 'upper' ,
494
+ 'zfill' ]
490
495
for method in self_methods :
491
496
collector (method , self_object )
492
497
@@ -514,6 +519,7 @@ def get_object(self):
514
519
def get_definition_location (self ):
515
520
return (None , None )
516
521
522
+
517
523
class Iterator (pyobjects .AbstractClass ):
518
524
519
525
def __init__ (self , holding = None ):
@@ -539,7 +545,8 @@ def __init__(self, holding=None):
539
545
self .holding = holding
540
546
self .attributes = {
541
547
'next' : BuiltinName (BuiltinFunction (self .holding )),
542
- '__iter__' : BuiltinName (BuiltinFunction (get_iterator (self .holding ))),
548
+ '__iter__' : BuiltinName (BuiltinFunction (
549
+ get_iterator (self .holding ))),
543
550
'close' : BuiltinName (BuiltinFunction ()),
544
551
'send' : BuiltinName (BuiltinFunction ()),
545
552
'throw' : BuiltinName (BuiltinFunction ())}
@@ -556,10 +563,10 @@ def get_returned_object(self, args):
556
563
class File (BuiltinClass ):
557
564
558
565
def __init__ (self ):
559
- self_object = pyobjects .PyObject (self )
560
566
str_object = get_str ()
561
567
str_list = get_list (get_str ())
562
568
attributes = {}
569
+
563
570
def add (name , returned = None , function = None ):
564
571
builtin = getattr (file , name , None )
565
572
attributes [name ] = BuiltinName (
@@ -587,7 +594,8 @@ def __init__(self, fget=None, fset=None, fdel=None, fdoc=None):
587
594
'fget' : BuiltinName (BuiltinFunction ()),
588
595
'fset' : BuiltinName (pynames .UnboundName ()),
589
596
'fdel' : BuiltinName (pynames .UnboundName ()),
590
- '__new__' : BuiltinName (BuiltinFunction (function = _property_function ))}
597
+ '__new__' : BuiltinName (
598
+ BuiltinFunction (function = _property_function ))}
591
599
super (Property , self ).__init__ (property , attributes )
592
600
593
601
def get_property_object (self , args ):
@@ -631,7 +639,7 @@ def get_attributes(self):
631
639
return {}
632
640
633
641
def get_name (self ):
634
- return 'lambda'
642
+ return 'lambda'
635
643
636
644
def get_param_names (self , special_args = True ):
637
645
result = [node .id for node in self .arguments .args
@@ -671,7 +679,7 @@ def _infer_sequence_for_pyname(pyname):
671
679
iter = obj .get_returned_object (args )
672
680
if iter is not None and 'next' in iter :
673
681
holding = iter ['next' ].get_object ().\
674
- get_returned_object (args )
682
+ get_returned_object (args )
675
683
return holding
676
684
677
685
@@ -690,12 +698,15 @@ def _create_builtin(args, creator):
690
698
def _range_function (args ):
691
699
return get_list ()
692
700
701
+
693
702
def _reversed_function (args ):
694
703
return _create_builtin (args , get_iterator )
695
704
705
+
696
706
def _sorted_function (args ):
697
707
return _create_builtin (args , get_list )
698
708
709
+
699
710
def _super_function (args ):
700
711
passed_class , passed_self = args .get_arguments (['type' , 'self' ])
701
712
if passed_self is None :
@@ -709,6 +720,7 @@ def _super_function(args):
709
720
return pyobjects .PyObject (supers [0 ])
710
721
return passed_self
711
722
723
+
712
724
def _zip_function (args ):
713
725
args = args .get_pynames (['sequence' ])
714
726
objects = []
@@ -721,6 +733,7 @@ def _zip_function(args):
721
733
tuple = get_tuple (* objects )
722
734
return get_list (tuple )
723
735
736
+
724
737
def _enumerate_function (args ):
725
738
passed = args .get_pynames (['sequence' ])[0 ]
726
739
if passed is None :
@@ -730,6 +743,7 @@ def _enumerate_function(args):
730
743
tuple = get_tuple (None , holding )
731
744
return get_iterator (tuple )
732
745
746
+
733
747
def _iter_function (args ):
734
748
passed = args .get_pynames (['sequence' ])[0 ]
735
749
if passed is None :
@@ -738,6 +752,7 @@ def _iter_function(args):
738
752
holding = _infer_sequence_for_pyname (passed )
739
753
return get_iterator (holding )
740
754
755
+
741
756
def _input_function (args ):
742
757
return get_str ()
743
758
@@ -751,17 +766,25 @@ def _input_function(args):
751
766
'file' : BuiltinName (get_file_type ()),
752
767
'open' : BuiltinName (get_file_type ()),
753
768
'unicode' : BuiltinName (get_str_type ()),
754
- 'range' : BuiltinName (BuiltinFunction (function = _range_function , builtin = range )),
755
- 'reversed' : BuiltinName (BuiltinFunction (function = _reversed_function , builtin = reversed )),
756
- 'sorted' : BuiltinName (BuiltinFunction (function = _sorted_function , builtin = sorted )),
757
- 'super' : BuiltinName (BuiltinFunction (function = _super_function , builtin = super )),
758
- 'property' : BuiltinName (BuiltinFunction (function = _property_function , builtin = property )),
769
+ 'range' : BuiltinName (BuiltinFunction (function = _range_function ,
770
+ builtin = range )),
771
+ 'reversed' : BuiltinName (BuiltinFunction (function = _reversed_function ,
772
+ builtin = reversed )),
773
+ 'sorted' : BuiltinName (BuiltinFunction (function = _sorted_function ,
774
+ builtin = sorted )),
775
+ 'super' : BuiltinName (BuiltinFunction (function = _super_function ,
776
+ builtin = super )),
777
+ 'property' : BuiltinName (BuiltinFunction (function = _property_function ,
778
+ builtin = property )),
759
779
'zip' : BuiltinName (BuiltinFunction (function = _zip_function , builtin = zip )),
760
- 'enumerate' : BuiltinName (BuiltinFunction (function = _enumerate_function , builtin = enumerate )),
780
+ 'enumerate' : BuiltinName (BuiltinFunction (function = _enumerate_function ,
781
+ builtin = enumerate )),
761
782
'object' : BuiltinName (BuiltinObject ()),
762
783
'type' : BuiltinName (BuiltinType ()),
763
- 'iter' : BuiltinName (BuiltinFunction (function = _iter_function , builtin = iter )),
764
- 'raw_input' : BuiltinName (BuiltinFunction (function = _input_function , builtin = raw_input )),
765
- }
784
+ 'iter' : BuiltinName (BuiltinFunction (function = _iter_function ,
785
+ builtin = iter )),
786
+ 'raw_input' : BuiltinName (BuiltinFunction (function = _input_function ,
787
+ builtin = raw_input )),
788
+ }
766
789
767
790
builtins = BuiltinModule ('__builtin__' , initial = _initial_builtins )
0 commit comments