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

Add support for showing all overload signatures #665

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

daemontus
Copy link

@daemontus daemontus commented Jan 23, 2024

This PR should solve #442 by displaying each overload type signature as a separate indented block after the "main" method signature.

So far, this works fine on my own project (which uses PyO3, so I am also testing it with overloads in stub files). But I am relatively new to pdoc, so I am not sure what level of testing is expected for this to be merged. Would it be sufficient to add an overloaded method to tests/testdata/misc_py311.py to see how it renders, or is there something more detailed that needs to be done?

Edit: I see that it is required to have 100% test coverage on the latest Python version. However, this feature is only available from Python 3.11 onward. So I've added a little compatibility shim which just returns an empty value on older Python versions (not ideal, but probably the best option). But this shim is not triggered on the newer Python versions, hence there is no way to get 100% coverage, even if I fix the other uncovered lines.

@daemontus
Copy link
Author

daemontus commented Jan 23, 2024

Ok, never mind... this still does not work with stub files when the stub file only contains the override signatures and the main file contains the "base" declaration... Bear with me, I'll need to test this a bit more...

Edit: I'll just make a note for myself that I need to look at test/testdata/type_stub.py and ensure that both overloads are correctly visible, plus the "main" method signature. At the moment, this does work only if the .pyi file also contains the main method signature, not only the overloads. However, that is not recommended by mypy. On the other hand, if I remove the main method signature, the overloads are not always correctly recognized (e.g. in my native PyO3 project), or they are recognized but the main signature is broken (in the type_stub.py test).

Edit2: The get_overloads shim should be moved to _compat.py.

@mhils
Copy link
Member

mhils commented Feb 12, 2024

(Happy to look at this once you mark it as ready)

@daemontus
Copy link
Author

Thanks! Unfortunately, I'll have to come back to this a bit later... the current implementation works as long as both the "base" method and its overloads are all declared in the stub file. But that is not the recommended way of doing things (e.g. mypy will report this as an error): the stub file should only contain the overloads, not the base method.

The issue is that once the overloads are in the stub file without the base method, they don't seem to be accessible through the built-in get_overloads function. When debugging, I can see them in the internal data-structures of the typing module, but I can't seem to find an "official" way to access them. Maybe it is a bug, but I am not that well versed in Python, so I might just be missing something. Anyway, I'll need to investigate further...

@mhils mhils marked this pull request as draft July 10, 2024 18:16
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