Commits

Jason R. Coombs committed 9980f72

Added .insert on lists

  • Participants
  • Parent commits 88276db
  • Tags 2.1

Comments (0)

Files changed (2)

File limpy/test/test_ops_and_types.py

 	assert vars['num1'] == int
 	assert vars['num2'] == int
 
+	# test insertion
+	vars, code = check("x = [1, 3, 4]; x.insert(1, 2)")
+
 def test_dicts():
 	assert "Dict({100: 'this'})" in check_code("{100:'this'}")
 

File limpy/types.py

 BASE_TYPESPEC.add_method(ListOfInt, 'pop', Signature([],[IIntType],None, int))
 BASE_TYPESPEC.add_method(ListOfInt, 'count', Signature([IIntType],[],None, int))
 BASE_TYPESPEC.add_method(ListOfInt, 'remove', Signature([IIntType],[],None, NoneType))
+BASE_TYPESPEC.add_method(ListOfInt, 'insert',
+	Signature([IIntType, IIntType], [], None, NoneType))
 BASE_TYPESPEC.add_op(ListOfInt, '+', [(IListOfIntType, ListOfInt)])
 BASE_TYPESPEC.add_op(ListOfInt, '*', [(IIntType, ListOfInt)])
 BASE_TYPESPEC.add_op(ListOfInt, '!=', [(IListOfIntType, bool)])
 BASE_TYPESPEC.add_method(ListOfStr, 'append', Signature([IStringType],[],None, NoneType))
 BASE_TYPESPEC.add_method(ListOfStr, 'pop', Signature([],[IIntType],None, str))
 BASE_TYPESPEC.add_method(ListOfStr, 'count', Signature([IStringType],[],None, int))
+BASE_TYPESPEC.add_method(ListOfStr, 'insert',
+	Signature([IIntType, IStringType], [], None, NoneType))
 BASE_TYPESPEC.add_op(ListOfStr, '+', [(IListOfStringType, ListOfStr)])
 BASE_TYPESPEC.add_op(ListOfStr, '*', [(IIntType, ListOfStr)])
 BASE_TYPESPEC.add_op(ListOfStr, '!=', [(IListOfStringType, bool)])