[docutils:patches] #212 Simplify type hints for readers, parsers, writers modules.

Günter Milde via Docutils-develop <[email protected]> Sun, 20 Oct 2024 19:52:52 -0000
Newsgroups gmane.text.docutils.devel
Message-ID </p/docutils/patches/212/79368225d224c0277628a868df7f0596400244b1.patches@docutils.p.sourceforge.net>
- **status**: open --> closed-fixed
- **Comment**:

Patches are commited in	[r9956].



---

**[patches:#212] Simplify type hints for readers, parsers, writers modules.**

**Status:** closed-fixed
**Group:** None
**Created:** Fri Oct 04, 2024 10:50 AM UTC by Günter Milde
**Last Updated:** Fri Oct 04, 2024 12:20 PM 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 [email protected] 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.