Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple documentation items with the same name #63

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

lmoureaux
Copy link
Contributor

@lmoureaux lmoureaux commented Dec 29, 2024

The architecture of doxylink was based on a name:item dict, which doesn't support storing multiple items with the same name. This lead to several workarounds:

  • To support overloaded functions, function items were turned to name:FunctionList;
  • To prevent friend declarations from conflicting with classes, friends were skipped.

Issues remained nevertheless: C++ allows declaring a class, a function, and a variable with the same name:

int a;
void a();
class a;

In addition, a common pattern with Qt is to declare properties with the same name as the getter (Qt itself does this all the time):

class Foo: public QObject
{
    Q_OBJECT
    Q_PROPERTY(int bar READ bar)
public:
    int bar() const;
};

In all the above examples, doxylink was just crashing when parsing the Doxygen index.

Instead of adding new exceptions, this commit changes the architecture to allow multiple symbols with the same name. Duplicate names may still raise an error, but only when one tries to refer to such an entry. This means that all other symbols in the project can now be used instead of failing during initialisation.

With this PR, it should be possible to create a domain in the future, supporting much of the same syntax as the built-in cpp domain

Supersedes #13.
Closes #54.

The architecture of doxylink was based on a name:item dict, which
doesn't support storing multiple items with the same name. This lead to
several workarounds:
* To support overloaded functions, function items were turned to
  name:FunctionList;
* To prevent friend declarations from conflicting with classes, friends
  were skipped.

Issues remained nevertheless: C++ allows declaring a class, a function,
and a variable with the same name:

    int a;
    void a();
    class a;

In addition, a common pattern with Qt is to declare properties with the
same name as the getter (Qt itself does this all the time):

    class Foo: public QObject
    {
        Q_OBJECT
	Q_PROPERTY(int bar READ bar)
    public:
        int bar() const;
    };

In all the above examples, doxylink was just crashing when parsing the
Doxygen index.

Instead of adding new exceptions, this commit changes the architecture
to allow multiple symbols with the same name. Duplicate names may still
raise an error, but only when one tries to refer to such an entry. This
means that all other symbols in the project can now be used instead of
failing during initialisation.

With this PR, it should be possible to create a domain in the future,
supporting much of the same syntax as the built-in [cpp
domain](https://www.sphinx-doc.org/en/master/usage/domains/cpp.html#cross-referencing)

Supersedes sphinx-contrib#31.
Closes sphinx-contrib#54.
sphinxcontrib/doxylink/doxylink.py Outdated Show resolved Hide resolved
sphinxcontrib/doxylink/doxylink.py Outdated Show resolved Hide resolved
sphinxcontrib/doxylink/doxylink.py Show resolved Hide resolved
sphinxcontrib/doxylink/doxylink.py Show resolved Hide resolved
sphinxcontrib/doxylink/doxylink.py Outdated Show resolved Hide resolved
bisect.bisect_left(..., key=) is only since Python 3.10.
list[T] is only since Python 3.9.

Silenced mypy warnings:
* Entry derives from tuple through namedtuple, but __lt__ has a more
  restrictive signature. Ignoring because the namedtuple parent is an
  implementation detail.
* mypy doesn't understand the bisect_left() call even though it is valid
  and works. I'm not entirely sure what causes this.
@lmoureaux
Copy link
Contributor Author

Added support for Python < 3.10 (supposedly, the pipeline will tell).

I had a small issues with this line:

start = bisect.bisect_left(self._entries, name[::-1])

MyPy complains as follows:

sphinxcontrib/doxylink/doxylink.py:161: error: Value of type variable "SupportsRichComparisonT" of "bisect_left" cannot be "Sequence[Any]"  [type-var]

I think this is a bug in typeshed and I reported it here. For now I just silenced the type checker.

I also silenced a MyPy warning for Entry.__lt__, which appears because I inherit from tuple. I don't consider the base class part of the API so this warning doesn't bother me.

@JasperCraeghs JasperCraeghs merged commit 3060ac5 into sphinx-contrib:master Jan 10, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Extension error on double definition
2 participants