Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

py2scala -- Use scala compiler for static analysis of well-typed python

Author: Dan Connolly
Copyright: Dan Connolly and the University of Kansas Medical Center
license:MIT

Usage

Convert one module:

$ python py2scala/p2s.py my_module.py >my_module.scala
TODO:Test, document --package option.

Testing

Tests are set up to run under nose, assuming fsc, the fast scala compiler, is installed:

py2scala$ nosetests
..................
../src/test/scala-err/distant_types.scala:23: error: value % is not a member of Any
  if ((x % 2) == 0) { 1 } else { "abc" }
         ^
./src/test/scala-err/distant_types.scala:31: error: type mismatch;
 found   : Any
 required: Seq[?]
    len(f1(x))
        ^
two errors found
.
----------------------------------------------------------------------
Ran 20 tests in 5.243s

OK

Alternatively, to test that the conversion works (i.e. doesn't crash):

py2scala$ python -m py2scala.test.test_convert

And to test compilation output with fsc:

py2scala$ python -m py2scala.test.test_well_typed

Object Capability Discipline

This code follows* a security and testing discipline where module-level code uses only authority passed to it by callers. Only the top level script environment is trusted with the full authority of the python standard library.

*mostly. There's an apparent conflict between object capability discipine and test discovery that I haven't worked out.

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.