@@ -51,11 +51,9 @@ good error message.
51
51
52
52
Here are some major things that aren't yet supported in compiled code:
53
53
54
- * Many dunder methods (only some work, such as ` __init__ ` and ` __eq__ ` )
54
+ * Some dunder methods (most work though )
55
55
* Monkey patching compiled functions or classes
56
56
* General multiple inheritance (a limited form is supported)
57
- * Named tuple defined using the class-based syntax
58
- * Defining protocols
59
57
60
58
We are generally happy to accept contributions that implement new Python
61
59
features.
@@ -73,16 +71,16 @@ compiled code. For example, you may want to do interactive testing or
73
71
to run benchmarks. This is also handy if you want to inspect the
74
72
generated C code (see Inspecting Generated C).
75
73
76
- Run ` mypyc ` to compile a module to a C extension using your
74
+ Run ` python -m mypyc` to compile a module to a C extension using your
77
75
development version of mypyc:
78
76
79
77
```
80
- $ mypyc program.py
78
+ $ python -m mypyc program.py
81
79
```
82
80
83
81
This will generate a C extension for ` program ` in the current working
84
- directory. For example, on a Linux system the generated file may be
85
- called ` program.cpython-37m-x86_64-linux-gnu .so ` .
82
+ directory. For example, on a macOS system the generated file may be
83
+ called ` program.cpython-313-darwin .so ` .
86
84
87
85
Since C extensions can't be run as programs, use ` python3 -c ` to run
88
86
the compiled module as a program:
@@ -95,7 +93,7 @@ Note that `__name__` in `program.py` will now be `program`, not
95
93
` __main__ ` !
96
94
97
95
You can manually delete the C extension to get back to an interpreted
98
- version (this example works on Linux):
96
+ version (this example works on macOS or Linux):
99
97
100
98
```
101
99
$ rm program.*.so
@@ -114,9 +112,9 @@ extensions) in compiled code.
114
112
115
113
Mypyc will only make compiled code faster. To see a significant
116
114
speedup, you must make sure that most of the time is spent in compiled
117
- code -- and not in libraries, for example .
115
+ code, and not in libraries or I/O .
118
116
119
- Mypyc has these passes:
117
+ Mypyc has these main passes:
120
118
121
119
* Type check the code using mypy and infer types for variables and
122
120
expressions. This produces a mypy AST (defined in ` mypy.nodes ` ) and
@@ -193,13 +191,13 @@ information. See the test cases in
193
191
` mypyc/test-data/irbuild-basic.test ` for examples of what the IR looks
194
192
like in a pretty-printed form.
195
193
196
- ## Testing overview
194
+ ## Testing Overview
197
195
198
196
Most mypyc test cases are defined in the same format (` .test ` ) as used
199
197
for test cases for mypy. Look at mypy developer documentation for a
200
198
general overview of how things work. Test cases live under
201
199
` mypyc/test-data/ ` , and you can run all mypyc tests via `pytest
202
- -q mypyc` . If you don't make changes to code under ` mypy/`, it's not
200
+ mypyc` . If you don't make changes to code under ` mypy/`, it's not
203
201
important to regularly run mypy tests during development.
204
202
205
203
You can use ` python runtests.py mypyc-fast ` to run a subset of mypyc
@@ -228,7 +226,7 @@ We also have tests that verify the generate IR
228
226
229
227
## Type-checking Mypyc
230
228
231
- ` ./runtests.py self ` type checks mypy and mypyc. This is pretty slow,
229
+ ` ./runtests.py self ` type checks mypy and mypyc. This is a little slow,
232
230
however, since it's using an uncompiled mypy.
233
231
234
232
Installing a released version of mypy using ` pip ` (which is compiled)
@@ -311,7 +309,7 @@ number of components at once, insensitive to the particular details of
311
309
the IR), but there really is no substitute for running code. You can
312
310
also write tests that test the generated IR, however.
313
311
314
- ### Tests that compile and run code
312
+ ### Tests That Compile and Run Code
315
313
316
314
Test cases that compile and run code are located in
317
315
` mypyc/test-data/run*.test ` and the test runner is in
@@ -364,15 +362,48 @@ Test cases can also have a `[out]` section, which specifies the
364
362
expected contents of stdout the test case should produce. New test
365
363
cases should prefer assert statements to ` [out] ` sections.
366
364
367
- ### IR tests
365
+ ### Debuggging Segfaults
366
+
367
+ If you experience a segfault, it's recommended to use a debugger that supports
368
+ C, such as gdb or lldb, to look into the segfault.
369
+
370
+ If a test case segfaults, you can run tests using the debugger, so
371
+ you can inspect the stack:
372
+
373
+ ```
374
+ $ pytest mypyc -n0 -s --mypyc-debug=gdb -k <name-of-test>
375
+ ```
376
+
377
+ You must use ` -n0 -s ` to enable interactive input to the debugger.
378
+ Instad of ` gdb ` , you can also try ` lldb ` .
379
+
380
+ To get better C stack tracebacks and more assertions in the Python
381
+ runtime, you can build Python in debug mode and use that to run tests
382
+ or debug outside the test framework.
383
+
384
+ Here are some hints that may help (for Ubuntu):
385
+
386
+ ```
387
+ $ sudo apt install gdb build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev libbz2-dev libffi-dev libgdbm-compat-dev
388
+ $ <download Python tarball and extract it>
389
+ $ cd Python-3.XX.Y
390
+ $ ./configure --with-pydebug
391
+ $ make -s -j16
392
+ $ ./python -m venv ~/<venv-location>
393
+ $ source ~/<venv-location>/bin/activate
394
+ $ cd <mypy-repo-dir>
395
+ $ pip install -r test-requirements.txt
396
+ ```
397
+
398
+ ### IR Tests
368
399
369
400
If the specifics of the generated IR of a change is important
370
401
(because, for example, you want to make sure a particular optimization
371
402
is triggering), you should add a ` mypyc.irbuild ` test as well. Test
372
403
cases are located in ` mypyc/test-data/irbuild-*.test ` and the test
373
404
driver is in ` mypyc.test.test_irbuild ` . IR build tests do a direct
374
405
comparison of the IR output, so try to make the test as targeted as
375
- possible so as to capture only the important details. (Many of our
406
+ possible so as to capture only the important details. (Some of our
376
407
existing IR build tests do not follow this advice, unfortunately!)
377
408
378
409
If you pass the ` --update-data ` flag to pytest, it will automatically
0 commit comments