Skip to content

Types created with NewType are rendered poorly. #41

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
bovlb opened this issue May 1, 2018 · 3 comments · Fixed by #64
Closed

Types created with NewType are rendered poorly. #41

bovlb opened this issue May 1, 2018 · 3 comments · Fixed by #64

Comments

@bovlb
Copy link

bovlb commented May 1, 2018

If I have code like:

    Foo = typing.NewType('Foo', str)
    def bar(x: Foo):
        pass

then its parameter gets documented as:

    x (<function NewType.<locals>.new_type at 0x7f644b4c6488>)

I was expecting something like one of the following:

    x (Foo)
    x (Foo alias for str)
    x (str)
@tibnor tibnor mentioned this issue Jun 14, 2018
@thigm85
Copy link

thigm85 commented Aug 14, 2018

I am having the same problem here :/

@okomestudio
Copy link

I'm having the same issue here.

If the choice of output rendering is what's holding #45 back from being merged, my vote would probably be on x (Foo) in the examples above, as x (Foo alias for str) looks very verbose, which might defeat the purpose of aliasing, and x (str) does not look like it takes advantage of aliasing at all.

@exhuma
Copy link

exhuma commented Nov 14, 2018

@okomestudio I think it's good to leave the information about str in there somehow. How would someone read the docs know that passing a string is acceptable if that information is missing?

For example if you have code like:

Foo = NewType('Foo', str)
def foo(x: Foo) -> None:
    print(x)

Then it is legal to write:

foo('hello world')

But if the docs only say that you can pass an instance of type Foo, then the reader of the docs has no clue that passing a str is also fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants