Closed jl-wynen closed 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):
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.
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.)
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](https://github.com/scipp/copier_template/assets/11393224/17ceaff3-71c1-454d-aa9e-90281af58a22)
becomes this:![after](https://github.com/scipp/copier_template/assets/11393224/26d7ef4b-3c72-4505-95cc-b91db1d42dc5)
But it does not handle![before2](https://github.com/scipp/copier_template/assets/11393224/809483c0-438a-46dc-b0d2-619163a4f06b)
TypeVar
. So this:becomes this:![after2](https://github.com/scipp/copier_template/assets/11393224/b36765a1-73b8-4844-ad54-9d8dfc6f9540)