zsol / py.wtf

Autogenerated reference docs for PyPI packages
https://py.wtf
MIT License
10 stars 3 forks source link

Show fancy type hints #77

Open zsol opened 2 years ago

zsol commented 2 years ago

Instead of

Callable[[a, b], c]
Union[a, b]

Let's show

(a, b) -> c
a | b

And maybe even

Tuple[a, b, ...]
# should turn into
(a, b, ...)
zsol commented 2 years ago

One approach on the indexer side is to introduce

Annotation = Arrow | Bars | Type

@dataclass
class Arrow:
  params: list[Annotation]
  returns: Annotation

@dataclass
class Bars:
  terms: list[Annotation]  # always at least 2 items

And then the indexer would translate all Union[...] and Callable[...] annotations into Bars and Arrow structures. This would get rid of the ugly edge case described in #8 for callables:

Callable[[], returns]

# =>

Type("Callable", xref, params=[
  Type("", None, params=[]),  # this would no longer happen
  Type("returns", None, None),
])