Skip to content

Support PEP 484 type hints #6

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

Closed
nicoonoclaste opened this issue Jan 22, 2019 · 9 comments
Closed

Support PEP 484 type hints #6

nicoonoclaste opened this issue Jan 22, 2019 · 9 comments
Labels
enhancement New feature or request

Comments

@nicoonoclaste
Copy link

Expected Behavior

When generating doc for a package that is annotated with PEP 484 type hints, I would expect the type hints to be present in the documentation.

For example, the following definition

def foo(x: Bar, repeat : int = 1):
    """Foo-cate a Bar a number of times (default: 1)."""
    ...

results in the type hints being available in the REPL's help():

>>> help(foo)
foo(x: __main__.Bar, repeat: int = 1)
    Foo-cate a Bar a number of times (default: 1).

and it should well as be present in the pdoc-generated documents:

$ pdoc example.py
Module example
==============

Functions
---------

`foo(x: Bar, repeat: int = 1)`
:   Foo-cate a Bar a number of times (default: 1).

Classes
-------

`Bar`

Actual Behavior

pdoc ignores the type-hints:

$ pdoc example.py
Module example
==============

Functions
---------

`foo(x, repeat=1)`
:   Foo-cate a Bar a number of times (default: 1).

Classes
-------

`Bar`

Type hints document the expected types of parameters and return values. As such, they convey a lot of information for the documentation's user, when present.

See PEP 484 for a discussion of type hints.

Steps to Reproduce

Generate documentation for a module that uses type hints

Additional info

  • pdoc version: 0.5.1
  • Python version: 3.7.2 (default, Jan 3 2019, 02:55:40)
@kernc
Copy link
Member

kernc commented Jan 23, 2019

Would you be interested in doing a pull request for that?

You would need to

@kernc kernc added the enhancement New feature or request label Jan 27, 2019
@nicoonoclaste
Copy link
Author

@kernc Sorry, I had entirely missed you replied here. Yes, obviously I'm pretty interested in writing the code for this ^.^

@omtinez
Copy link

omtinez commented Apr 7, 2019

@nbraud do you plan on submitting a PR with your commit?

@kernc
Copy link
Member

kernc commented Apr 10, 2019

@omtinez PR #7 is in progress. Welcome to continue where it's left off.

@kernc kernc closed this as completed in 5df06cd Apr 21, 2019
@kernc kernc reopened this Apr 22, 2019
@kernc
Copy link
Member

kernc commented Apr 22, 2019

This is not done. Text template doesn't look into config.mako nor does it print types by default. I'll see what I can do about that and about hyperlinking documented types in HTML output.

@kernc
Copy link
Member

kernc commented Apr 24, 2019

Hyperlinked types testable with:

pdoc --html -c show_type_annotations=True your_module

@DaniGuardiola
Copy link

DaniGuardiola commented Sep 9, 2019

Types are not showing up on my project. Fresh pdoc3 install so I assume it is the latest version published, testing it with --http option. Am I missing something? Thanks :)

Edit: didn't read the previous comment. Adding -c show_type_annotations=True worked. I didn't find anything about this option in the documentation though. Also I think the CLI option could be nicer, something like --types / -t.

@DaniGuardiola
Copy link

After some more testing I've seen it works pretty well, nice!

I have a couple of suggestions:

  • Class / instance property and variable types are not being documented.
  • Standard library types could be linked to the official online documentation, specially the Typings library.

@kernc
Copy link
Member

kernc commented Sep 9, 2019

@DaniGuardiola, care to open a new issue for missing variable/property annotations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

4 participants