google / google/python-fire

`fire.Fire()` not work with functions in cython compiled .pyd file

Offen
#208 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
28.2k
Forks
1.5k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Hi, i have a foo.py file compiled to foo.pyd by cython,
then use `fire.Fire()` to make it a cli like below,
instead output `1 2 3` i get `2 3 3`,
seems because cython treat functions as `PyObject` with first argument `self` after i checked the generated .c file.
any idea to make this work except wrap it one by one by another normal python function ? (not want to wrap because maybe many functions in foo.py later and bar.py will be compiled to bar.pyd called by another main.py, then the wrapper become cython function too...)

```python
# bar.py
from foo import * # import from foo.pyd not foo.py
fire.Fire()
```

```python
# foo.py
def test_fn(a=1, b=2, c=3):
print(a, b, c)
```

```c
// foo.c for foo.pyd
`static PyObject *__pyx_pw_19test_fn_3foo_1foo(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { ...}`
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.