Skip to content

Added support for reading argparse instances inside classes#93

Open
fixeria wants to merge 1 commit intosphinx-doc:mainfrom
fixeria:inside-classes
Open

Added support for reading argparse instances inside classes#93
fixeria wants to merge 1 commit intosphinx-doc:mainfrom
fixeria:inside-classes

Conversation

@fixeria
Copy link
Copy Markdown

@fixeria fixeria commented Apr 12, 2026

Currently, sphinx-argparse can only read argparse instances from global variables/attributes within a module. This patch introduces the ability to specify a dotted path in :func: (e.g. Foo.Bar.parser) to reach ArgumentParser instances defined as class attributes.

This is useful for CLI/REPL interfaces built with modules like cmd2, where argparse parsers are defined inside command handler classes.

This is a follow-up to #36 (comment) and #60.

Currently, sphinx-argparse can only read argparse instances from
global variables/attributes within a module.  This patch introduces
the ability to specify a dotted path in ':func:' (e.g. 'Foo.Bar.parser')
to reach ArgumentParser instances defined as class attributes.

This is useful for CLI/REPL interfaces built with modules like 'cmd2',
where argparse parsers are defined inside command handler classes.

Initial patch by: Harald Welte <laforge@osmocom.org>
Co-authored by: Vadim Yanitskiy <fixeria@osmocom.org>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 12, 2026

Codecov Report

❌ Patch coverage is 39.28571% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.22%. Comparing base (528aa98) to head (c9d2c8a).

Files with missing lines Patch % Lines
test/sample-inside-class.py 0.00% 10 Missing ⚠️
sphinxarg/ext.py 61.11% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   50.19%   50.22%   +0.03%     
==========================================
  Files          18       19       +1     
  Lines        1289     1306      +17     
  Branches      262      263       +1     
==========================================
+ Hits          647      656       +9     
- Misses        598      607       +9     
+ Partials       44       43       -1     
Flag Coverage Δ
unittests 50.00% <39.28%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fixeria
Copy link
Copy Markdown
Author

fixeria commented Apr 14, 2026

Hello @AA-Turner,

as you suggested in #36 (comment), we've created a new pull request with unit tests. Though, Codecov is complaining about low testing coverage. Is this acceptable or shall I work on extending the coverage? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants