You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change Docstring.params (and others) to be dict-like types #89
In order to make extracting the necessary attribute's docstring simpler, it would be great if it had a dict-like interface. attribute interface would also be great to have, but might require more sophisticated refactoring.
type hint should show Docstring.param as DocstringParams. Right now it just shows List[DocstringParam]. Or if you are talking about argument type hints, they are still available with
It's about (statically) type-hinting for argument1. Afaiu you don't have a way to type-hint dynamic attributes statically, while the dict case is handled by __getitem__. I haven't ecperimented with type-hinting __getattr__.
Maybe I'm missing something but would argument1 not be type DocstringParam? as would all the param attributes of DocstingParams. We're not type hinting with the arguments actual type anyways, its just a string parameter under type_name
I think dict-like access would be preferable. You could use a TypedDict or simply dict[str, DocstringParam] to accommodate for type hints. For backwards compatibility this could be an additional member instead of replacing params, e.g. params_dict or params_by_names.
Thanks all for the discussion on dict versus attribute access. This is fixed in #197, now on main, which adds params_by_name, attrs_by_name and raises_by_type: read-only mappings next to the existing lists, so doc.params_by_name["argument1"].description works and type checkers know what it returns. If a name is given twice, the first item wins, and the lists still have every item. I went with dict-style lookup rather than attributes for the typing reasons discussed above.
Activity
scarere commentedon Aug 7, 2024
Attribute interface would be better as it would be consistent with the rest of the api. Ei
Is cleaner than:
LecrisUT commentedon Aug 7, 2024
Unfortunately this would not play quite well with type-hints
scarere commentedon Aug 7, 2024
I'm not sure what you mean. Right now the Docstring class has attribute params with type List[DocstringParam]. Instead we could have
type hint should show Docstring.param as DocstringParams. Right now it just shows List[DocstringParam]. Or if you are talking about argument type hints, they are still available with
LecrisUT commentedon Aug 7, 2024
It's about (statically) type-hinting for
argument1. Afaiu you don't have a way to type-hint dynamic attributes statically, while the dict case is handled by__getitem__. I haven't ecperimented with type-hinting__getattr__.scarere commentedon Aug 7, 2024
Maybe I'm missing something but would argument1 not be type DocstringParam? as would all the param attributes of DocstingParams. We're not type hinting with the arguments actual type anyways, its just a string parameter under type_name
ndahn commentedon Sep 6, 2024
I think dict-like access would be preferable. You could use a TypedDict or simply
dict[str, DocstringParam]to accommodate for type hints. For backwards compatibility this could be an additional member instead of replacing params, e.g.params_dictorparams_by_names.rr- commentedon Nov 7, 2026
Thanks all for the discussion on dict versus attribute access. This is fixed in #197, now on main, which adds
params_by_name,attrs_by_nameandraises_by_type: read-only mappings next to the existing lists, sodoc.params_by_name["argument1"].descriptionworks and type checkers know what it returns. If a name is given twice, the first item wins, and the lists still have every item. I went with dict-style lookup rather than attributes for the typing reasons discussed above.