From: Günter M. <mi...@us...> - 2024-10-04 12:20:42
|
Also the type hint `-> Any | _DefaultT` seems not to add any info over a simple `-> Any` for a function with name `get()` or `setdefault()` with a function argument named "default". Attachments: - [0001-Trim-down-overhead-of-type-hints-2.patch](https://sourceforge.net/p/docutils/patches/_discuss/thread/dcbb0a5e26/44c9/attachment/0001-Trim-down-overhead-of-type-hints-2.patch) (2.3 kB; text/x-patch) --- **[patches:#212] Simplify type hints for readers, parsers, writers modules.** **Status:** open **Group:** None **Created:** Fri Oct 04, 2024 10:50 AM UTC by Günter Milde **Last Updated:** Fri Oct 04, 2024 10:50 AM UTC **Owner:** nobody **Attachments:** - [0001-Trim-down-overhead-of-type-hints.patch](https://sourceforge.net/p/docutils/patches/212/attachment/0001-Trim-down-overhead-of-type-hints.patch) (12.6 kB; text/x-patch) Commits [r9872], [r9873], and [r9874] added type hints for the "readers", "parsers", and "writers" modules increasing their size by 42, 70, and 112 lines respectively. The reason is the provision of the exact output value for a set of specific input vales via the `@overload` decorator for the auxiliary functions `get_*_class()`. IMO, this is an overkill: the `@overload` is fine, if different types of input values result in different types of output values but not for individual values of the same type that return a class that is a subclass of a well defined abstract base class (readers.Reader, parsers.Parser, writers.Writer) and where the set of admissible values is not known (any 3rd party component is found, too). My argument is, that the `get_*_class()` function is intended for use when the component class is fetched at runtime from user configuration (which means we only know that the return value conforms to the interface of the abstract base class). In cases where a statical type checker knows the `reader_name`, `parser_name`, `writer_name` (and this matters) there is no need to use `get_*_class()` but the calling code may directly import the component class. Unless there is a convincing use case, I suggest the attached patch to reverse the changes to the `get_*_class()` functions. --- Sent from sourceforge.net because doc...@li... is subscribed to https://sourceforge.net/p/docutils/patches/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/patches/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |