scipp / copier_template

Copier template for Scipp projects
BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

Use custom typehint formatter #124

Closed jl-wynen closed 5 months ago

jl-wynen commented 5 months ago

Fixes #61

The docs don't show type aliases, so the refs that this generates don't work. I added them regardless for when we (hopefully) find a way to show aliases. I added the underlying type so that users can find out what types are actually required.

The result is still quite verbose. It could be made more compact by removing the module name. But then it is harder to find the definitions of the types.

With this change, this: before

becomes this: after


But it does not handle TypeVar. So this: before2

becomes this: after2

jl-wynen commented 5 months ago

Question: Can this be adapted so it also works nicely with Python 3.12 type aliases (I have not tried how those are rendered currently)?

It gets rendered in a bad way (my function does not apply to this case, so this is the default): py312

This uses

type Filename = str;
"""The name of a file."""

Mode = NewType("Mode", str)
"""File open mode"""

Flags: TypeAlias = int
""""File flags"""

Interestingly, the link to Mode works now. Maybe something changes in python 3.12?

I'll try and improve the rendering.

jl-wynen commented 5 months ago

I added handling of TypeAliasType. With the above dummy example, this produces the following. (I added a type parameter to Filename for testing. I there is no param, the [T] disappears.) p312-after