Skip to content

Using NewType doesn't play nice with sphinx docs #50

@davesque

Description

@davesque

Has anyone figured out a way around this? I generally don't use NewType because I think it's not necessary in the majority of cases, but I ran across this weird behavior recently when I got curious about how sphinx would represent function signatures with NewType annotations:

Index = NewType('Index', int)

def child_ext_private_key(self, i: Index) -> 'ExtPrivateKey':
    ...

...leads to this weirdness:
Screen Shot 2019-07-26 at 11 04 51 PM
Whereas doing things with a simple type alias:

Index = int

def child_ext_private_key(self, i: Index) -> 'ExtPrivateKey':
    ...

...behaves as expected:
Screen Shot 2019-07-26 at 11 05 00 PM
I would expect sphinx to represent a NewType with the name of the type e.g. Index in this case. But, honestly, even that seems problematic. Someone reading the docs won't know what an Index is supposed to be even though it's just an int. Even if there was documentation on a typing module that's part of a package, it doesn't seem reasonable for people to have to look up what is meant by a NewType annotation whenever they want to understand the API of a method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions