Commit Graph

24 Commits

Author SHA1 Message Date
William S Fulton 632cf8fee5 [Python] Unify class docstring under -builtin with non-builtin
The autodoc-class fallback in make_autodoc() and the no-docstring
fallback in classHandler() both emitted "::ClassName" under -builtin
where the non-builtin proxy module emits "Proxy of C++ ClassName class."
(or "" when no docstring source is in scope).

Collapse the AUTODOC_CLASS builtin branch so the autodoc-derived text
is identical in both modes, drop the classHandler -builtin block that
seeded feature:python:tp_doc with "::ClassName" when have_docstring is
false, and initialise quoted_tp_doc_str to an empty string rather than
the literal "0" so the tp_doc slot becomes "" instead of inheriting
SwigPyObject's docstring via the MRO lookup that inspect.getdoc() does
on a NULL tp_doc.

Drop the is_python_builtin() gates that this divergence had forced into
autodoc_runme.py, doxygen_autodoc_docstring_runme.py and
doxygen_misc_constructs_runme.py, plus the matching #ifdef
SWIGPYTHON_BUILTIN helpers in doxygen_autodoc_docstring.i and
doxygen_misc_constructs.i. The autodoc.i helper stays - autodoc_runme.py
still needs it to gate the _autodoc.* low-level checks that genuinely
do not exist under -builtin.

The autodoc-driven __init__ checks in autodoc_runme.py also drop their
skip=True guards: 2f8cdc412 already made cdocstring(node, AUTODOC_CTOR)
flow into python:tp_init_doc for autodoc-only constructors as well as
doxygen ones, so the descriptor adapter installs the expected
"__init__(self, ...) -> Foo" string in -builtin too.

Assisted-by: Claude Opus 4.7 (1M context)
2026-05-26 08:37:07 +01:00
William S Fulton 8c94f4e941 Fix python builtin test failure 2026-05-16 21:04:50 +01:00
William S Fulton 5fcb0ace4f Doxygen misc constructs: cover @{ group marker and /// @file variant
Adds two test fixtures to lock down the corner cases of the #3403 fix:

- SlashFileHeaderTestClass exercises the same @file bleed scenario but
  with single-line /// comments, which take a different scanner branch
  to //!.  Without the fix the file header would bleed into the class
  description in this style too.

- GroupedMembers exercises @name/@{ member grouping.  The discard rule
  must NOT fire here: @{ does not terminate the structural block (no
  blank line), so each member's own doc comment must still attach.  A
  regression here would either drop @{ or drop the per-member doc.

Java and Python runmes are kept in step.

Assisted-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-15 23:27:03 +01:00
Joachim Wuttke (o) d50e235551 Fix -doxygen: @file block bleeds into first class docstring
When a header uses consecutive `//!` (or `///`) single-line comments for a
file-level block starting with `@file`, SWIG's comment accumulation loop was
concatenating the file-header content into the following class or function
docstring.

Two bugs conspired:
- Only the `@file` line itself was recognised as structural and skipped;
  subsequent lines (`@brief`, `@authors`, ...) are not in `structuralTags[]`
  and so were accumulated into `yylval.str`.
- Blank lines between comment groups do not break the accumulation loop
  (all `SWIG_TOKEN_ENDLINE` tokens are consumed silently), so the next
  declaration's own doc comment was appended to the same string.

Fix: introduce an `in_structural_block` flag. When the first comment in a
group contains a structural command (`@file`, `@page`, ...), set the flag but
continue accumulating content normally. Count newlines in the inner do-while;
when `in_structural_block` is set and two or more consecutive newlines are seen
(a blank line), discard all accumulated content and break, so the following
declaration's doc comment is processed fresh.

Not breaking the loop on a natural exit (no blank line) is deliberate: it
correctly handles the `@name`/`@{` member-grouping pattern, where `@{`
immediately follows `@name` without a blank line and must still be attached to
the next member.

The block-comment style (`/*! @file ... */`) was already handled correctly
because the entire block is one scanner token and `isStructuralDoxygen()`
would see `@file` in it.

Fixes #3403
2026-05-15 23:24:44 +01:00
Vadim Zeitlin f57b096c92 Fix generated Python code for Doxygen comments with triple quotes
In addition to the changes in the previous commit, also avoid syntax
errors in the generated Python docstrings by splitting them into several
parts if there are 3 quotes in a row in the input, as it's impossible to
have them inside triple-quoted strings, generally speaking (i.e. if
there are occurrences of both """ and ''' inside the string).
2020-03-04 00:57:31 +01:00
Vadim Zeitlin b81cd1bdab Fix generated Python code for Doxygen comments ending with quote
Single-line Doxygen comments ending with a double quote resulted in
syntactically-invalid Python docstrings in the output, so use triple
single quotes as delimiters in this case to avoid it.
2020-03-04 00:56:27 +01:00
John McFarland fd33bdf8a5 Flag optional arguments in doxygen pydoc output
If the parameter has a default value, add the string ", optional" to
the parameter type description in the translated python comments.
Three examples with default values were already present in the test
cases, so their expected python output has been updated accordingly.
2019-08-07 16:42:39 -05:00
Dmitry D. Chernov fa5f519bf9 Test-suite: Unify string quoting in the Python sources 2019-07-14 12:58:21 +10:00
William S Fulton 8234656497 Correct python example headers 2018-05-25 23:35:28 +01:00
William S Fulton 95caf87596 PEP8 conformance for comment verifier module 2018-05-25 07:56:45 +01:00
Vadim Zeitlin 148bcab7a0 Switch Python Doxygen unit tests to use inspect.getdoc()
Using the standard inspect module instead of accessing __doc__ directly allows
the tests to pass both when using and not using -builtin, as whitespace-only
differences between the docstrings don't matter then because inspect.getdoc()
removes the indentation and the leading and trailing spaces.

This is similar to what had been already done for python_docstring unit test
in fa282b3540.
2016-12-12 01:26:05 +01:00
Vadim Zeitlin 45ecc9cb84 Fix trimming whitespace from Doxygen comments.
Also trim the string (making it empty) if it consists solely of whitespace.
2015-02-17 00:10:37 +01:00
Vadim Zeitlin 410b508e9a Don't indent Doxygen doc strings in generated Python code.
This is unnecessary and inconsistent with "builtin" case in which the
docstrings are not indented in the generated C++ code, thus making it
impossible to write tests working in both cases.

Most of the changes in this commit simply remove the extra whitespace from the
expected values in the tests.
2014-12-15 13:59:17 +01:00
Vadim Zeitlin 8b83976f4c Fix arguments of @param, @return etc translations to Python.
For the parameter documentation to be really taken as such, in its entirety,
by Sphinx, it must be indented relative to the :param: tag. Do this by
appending an extra indent after every line of the output and work around the
unnecessary indent of the last line by removing the trailing whitespace.

This required updating the existing tests and removing the expected but not
present any more whitespace from them, but as trailing whitespace in the
documentation is at best insignificant (and at worst harmful) anyhow, this is
not a big price to pay for simpler translator code.
2014-08-22 17:45:22 +02:00
Vadim Zeitlin 14ba3b8dd4 Preserve relative indentation when parsing Doxygen comments.
This is important to preserve the structure of the lists which appear
correctly in Python output without any additional effort if the indentation is
lost.

It is also makes the behaviour consistent for

	/**
	 *
	 *
	 */

comments and those without the asterisks in the middle lines, as now the
indentation is preserved in both cases while it was only preserved when the
asterisks were present previously.
2014-08-22 17:45:22 +02:00
Vadim Zeitlin dd4c680a02 Use Python-ish, not C++, parameter types in Python documentation.
Using C++ types in documentation for Python users is more harmful than
useless, so use Python types whenever possible and allow defining "doctype"
typemap to customize this for the user-defined types.
2014-08-22 17:45:22 +02:00
Vadim Zeitlin 7d2743a0bb Use reST inline markup in PyDocConverter instead of Markdown.
reST is standard Python markup, so use *...*, ``...`` and so on instead of
_..._, '...' etc.

No other changes even though the mapping of some Doxygen tags to markup used
for them seems suspicions (e.g. \var almost certainly should be the same as
\em).
2014-08-13 16:11:30 +02:00
Vadim Zeitlin b374aad0da Use Sphinx-compatible docstring format in PyDocConverter.
Use the more or less standard :param:, :type:, :return: and :raises: in the
function/methods descriptions.

Update the output expected from the Python tests accordingly.
2014-08-13 16:11:30 +02:00
Vadim Zeitlin 6cce652762 Merge latest master into doxygen branch again.
Update Doxygen-specific Python unit tests to work with the new indentation.

Update one of Doxygen-specific Java tests to still build with the new handling
of srcdir.
2014-08-13 16:11:21 +02:00
Marko Klopcic b5dea7456b improved handling of word commands if puntuation is following the word, preserved spaces at start of comment line 2013-02-21 09:05:11 +01:00
Marko Klopcic fa8fc4baf3 all doxygen tests pass 2013-02-15 23:05:14 +01:00
Marko Klopcic ee3e4024a6 updated test doxygen_misc_constructs for Python 2013-02-05 07:57:49 +01:00
Marko Klopcic 29d1bba70a improved comment formatting for Python 2013-02-02 23:01:09 +01:00
Marko Klopcic af74b4f96a renamed test case
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13726 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2012-08-27 20:25:00 +00:00