Commits

masklinn committed a2f78ee

Builtins should be built in

  • Participants
  • Parent commits 92250c2
  • Tags 0.4

Comments (0)

Files changed (2)

             : py.False;
     });
 
+    var PY_builtins = {
+        type: py.type,
+
+        None: py.None,
+        True: py.True,
+        False: py.False,
+
+        object: py.object,
+        bool: py.bool,
+        float: py.float,
+        tuple: py.tuple,
+        list: py.list,
+        dict: py.dict,
+        issubclass: py.issubclass
+    };
+
     py.parse = function (toks) {
         var index = 0;
         token = toks[0];
         throw new Error('SyntaxError: unknown comparator [[' + operator + ']]');
     };
     py.evaluate = function (expr, context) {
+        context = context || {};
         switch (expr.id) {
         case '(name)':
             var val = context[expr.value];
+            if (val === undefined && expr.value in PY_builtins) {
+                return PY_builtins[expr.value];
+            }
             return PY_ensurepy(val, expr.value);
         case '(string)':
             return new py.str(expr.value);

File test/test.js

         describe('strings', function () {
             it('should be true if non-empty', function () {
                 expect(py.eval('bool(date_deadline)',
-                               {bool: py.bool, date_deadline: '2008'}))
+                               {date_deadline: '2008'}))
                     .to.be(true);
             });
             it('should be false if empty', function () {
-                expect(py.eval('bool(s)', {bool: py.bool, s: ''}))
-                    .to.be(false);
+                expect(py.eval('bool(s)', {s: ''})) .to.be(false);
             });
         });
     });
     it('should say a type is its own subclass', function () {
         expect(py.issubclass.__call__(py.dict, py.dict).toJSON())
             .to.be(true);
-        expect(py.eval('issubclass(dict, dict)',
-                       {issubclass: py.issubclass, dict: py.dict}))
+        expect(py.eval('issubclass(dict, dict)'))
             .to.be(true);
     });
     it('should work with subtypes', function () {
             .to.be(true);
     });
 });
+describe('builtins', function () {
+    it('should aways be available', function () {
+        expect(py.eval('bool("foo")')).to.be(true);
+    });
+});