|
| 1 | +mypyc: Mypy to Python C Extension Compiler |
| 2 | +========================================== |
| 3 | + |
| 4 | +*Mypyc is (mostly) not yet useful for general Python development.* |
| 5 | + |
| 6 | +Mypyc is a compiler that compiles mypy-annotated, statically typed |
| 7 | +Python modules into CPython C extensions. Currently our primary focus |
| 8 | +is on making mypy faster through compilation -- the default mypy wheels |
| 9 | +are compiled with mypyc. Compiled mypy is about 4x faster than |
| 10 | +without compilation. |
| 11 | + |
| 12 | +Mypyc compiles what is essentially a Python language variant using "strict" |
| 13 | +semantics. This means (among some other things): |
| 14 | + |
| 15 | + * Most type annotations are enforced at runtime (raising ``TypeError`` on mismatch) |
| 16 | + |
| 17 | + * Classes are compiled into extension classes without ``__dict__`` |
| 18 | + (much, but not quite, like if they used ``__slots__``) |
| 19 | + |
| 20 | + * Monkey patching doesn't work |
| 21 | + |
| 22 | + * Instance attributes won't fall back to class attributes if undefined |
| 23 | + |
| 24 | + * Metaclasses not supported |
| 25 | + |
| 26 | + * Also there are still a bunch of bad bugs and unsupported features :) |
| 27 | + |
| 28 | +Compiled modules can import arbitrary Python modules, and compiled modules |
| 29 | +can be used from other Python modules. Typically mypyc is used to only |
| 30 | +compile modules that contain performance bottlenecks. |
| 31 | + |
| 32 | +You can run compiled modules also as normal, interpreted Python |
| 33 | +modules, since mypyc targets valid Python code. This means that |
| 34 | +all Python developer tools and debuggers can be used. |
| 35 | + |
| 36 | +macOS Requirements |
| 37 | +------------------ |
| 38 | + |
| 39 | +* macOS Sierra or later |
| 40 | + |
| 41 | +* Xcode command line tools |
| 42 | + |
| 43 | +* Python 3.5+ from python.org (other versions are untested) |
| 44 | + |
| 45 | +Linux Requirements |
| 46 | +------------------ |
| 47 | + |
| 48 | +* A recent enough C/C++ build environment |
| 49 | + |
| 50 | +* Python 3.5+ |
| 51 | + |
| 52 | +Windows Requirements |
| 53 | +-------------------- |
| 54 | + |
| 55 | +* Windows has been tested with Windows 10 and MSVC 2017. |
| 56 | + |
| 57 | +* Python 3.5+ |
| 58 | + |
| 59 | +Quick Start for Contributors |
| 60 | +---------------------------- |
| 61 | + |
| 62 | +First clone the mypy git repository *and git submodules*: |
| 63 | + |
| 64 | + $ git clone --recurse-submodules https://github.com/mypyc/mypy.git |
| 65 | + $ cd mypy |
| 66 | + |
| 67 | +Optionally create a virtualenv (recommended): |
| 68 | + |
| 69 | + $ virtualenv -p python3 <directory> |
| 70 | + $ source <directory>/bin/activate |
| 71 | + |
| 72 | +Then install the dependencies: |
| 73 | + |
| 74 | + $ python3 -m pip install -r test-requirements.txt |
| 75 | + |
| 76 | +Now you can run the tests: |
| 77 | + |
| 78 | + $ pytest mypyc |
| 79 | + |
| 80 | +Look at the [issue tracker](https://github.com/mypyc/mypyc/issues) |
| 81 | +for things to work on. Please express your interest in working on an |
| 82 | +issue by adding a comment before doing any significant work, since |
| 83 | +development is currently very active and there is real risk of duplicate |
| 84 | +work. |
| 85 | + |
| 86 | +Note that the issue tracker is still hosted on the mypyc project, not |
| 87 | +with mypy itself. |
| 88 | + |
| 89 | +Documentation |
| 90 | +------------- |
| 91 | + |
| 92 | +We have some [developer documentation](doc/dev-intro.md). |
| 93 | + |
| 94 | +Development Status and Roadmap |
| 95 | +------------------------------ |
| 96 | + |
| 97 | +These are the current planned major milestones: |
| 98 | + |
| 99 | +1. [DONE] Support a smallish but useful Python subset. Focus on compiling |
| 100 | + single modules, while the rest of the program is interpreted and does not |
| 101 | + need to be type checked. |
| 102 | + |
| 103 | +2. [DONE] Support compiling multiple modules as a single compilation unit (or |
| 104 | + dynamic linking of compiled modules). Without this inter-module |
| 105 | + calls will use slower Python-level objects, wrapper functions and |
| 106 | + Python namespaces. |
| 107 | + |
| 108 | +3. [DONE] Mypyc can compile mypy. |
| 109 | + |
| 110 | +4. [DONE] Optimize some important performance bottlenecks. |
| 111 | + |
| 112 | +5. [PARTIALLY DONE] Generate useful errors for code that uses unsupported Python |
| 113 | + features instead of crashing or generating bad code. |
| 114 | + |
| 115 | +6. [DONE] Release a version of mypy that includes a compiled mypy. |
| 116 | + |
| 117 | +7a. More feature/compatibility work. (100% compatibility with Python is distinctly |
| 118 | + an anti-goal, but more than we have now is a good idea.) |
| 119 | + |
| 120 | +7b. Support compiling Black, which is a prominent tool that could benefit |
| 121 | + and has maintainer buy-in. |
| 122 | + (Let us know if you maintain another Python tool or library and are |
| 123 | + interested in working with us on this!) |
| 124 | + |
| 125 | +7c. More optimization! Code size reductions in particular are likely to |
| 126 | + be valuable and will speed up mypyc compilation. |
| 127 | + |
| 128 | +8. We'll see! Adventure is out there! |
| 129 | + |
| 130 | +Future |
| 131 | +------ |
| 132 | + |
| 133 | +We have some ideas for |
| 134 | +[future improvements and optimizations](doc/future.md). |
0 commit comments