fix: use inspect for classmethod parameter signatures in createstubs#739
fix: use inspect for classmethod parameter signatures in createstubs#739Copilot wants to merge 6 commits into
Conversation
|
@copilot , Also i explicitly asked for a minimal change. At his point this PR is simply lacking quality and will be rejected unless you can address this properly |
Reworked in commit
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #739 +/- ##
==========================================
+ Coverage 72.36% 74.16% +1.80%
==========================================
Files 71 71
Lines 8399 7792 -607
Branches 1541 1428 -113
==========================================
- Hits 6078 5779 -299
+ Misses 1823 1562 -261
+ Partials 498 451 -47 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b54a9fc to
2da1cb6
Compare
Agent-Logs-Url: https://github.com/Josverl/micropython-stubber/sessions/37c2a12a-2bf2-4d21-8a9f-eed01edc9745 Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Josverl/micropython-stubber/sessions/37c2a12a-2bf2-4d21-8a9f-eed01edc9745 Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
…ve test
- createstubs.py: replace hardcoded 'cls, *args, **kwargs' with
params.replace('self', 'cls', 1) to use inspect-derived params
- mpy_inspect.py: add bound_method support to signature() with
bytecode-safety check to avoid segfault on native classmethods
- tests: rewrite classmethod tests using MicroPython-style bound_method mock
- tests: add native MicroPython test for inspect on classmethod
Agent-Logs-Url: https://github.com/Josverl/micropython-stubber/sessions/bbd26efa-d963-4041-9548-22581cc0519a
Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Josverl/micropython-stubber/sessions/bbd26efa-d963-4041-9548-22581cc0519a Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
2da1cb6 to
32eeff5
Compare
createstubs.pyusedinspectto extract signatures for regular functions/methods but always emittedcls, *args, **kwargsfor@classmethodmethods (detected asbound_methodon MicroPython), ignoring the inspect-derived params already computed above.Root cause
In the
bound_methodbranch ofwrite_object_stub, the inspect-derivedparamsvariable (computed just above) was discarded and replaced with a hardcodedcls, *args, **kwargsstring.Changes
src/stubber/board/createstubs.py(1-line change, propagated to all variants viamake-variants):cls, *args, **kwargswithparams.replace("self", "cls", 1)— uses the inspect-derived params when available, automatically falls back tocls, *args, **kwargswhen inspect is unavailable or failstests/data/mpy_inspect.py:signature()to supportbound_method(how classmethods appear on MicroPython) by extracting the underlying bytecode function from the bound_method memory layout (funat offset 1 inmp_obj_bound_meth_t)int.from_bytes; those raiseNotImplementedErrorand fall back gracefullytests/createstubs/inspect_test.py:test_classmethod_uses_inspect_for_signature: simulates MicroPython'sbound_methodtype using a CPython class namedbound_method; verifies actual param names are usedtest_classmethod_fallback_without_inspect: verifiescls, *args, **kwargsfallback when_use_inspect=Falsetests/native/native_inspect_test.py:test_classmethod_params_use_inspect: runs against the real MicroPython unix binary; verifies thatinspect.signature()returns the correct parameter count (includingcls) for a pure-Python classmethodBefore / After