[Rpm-maint] [rpm-software-management/rpm] Add type hints to the Python interface (#1615)
Jerry James
notifications at github.com
Thu Apr 1 16:57:33 UTC 2021
Great. Here is my thinking on the mypy errors noted above.
For the `hdr.__getattr__` case, I think those declarations should be replaced with a comment noting that an `rpmTag` or `AnyStr` value can be passed as an argument, and the corresponding `int` or `AnyStr` value will be the result. I don't see any way of convincing mypy to like the existing declarations. (See `TypeChecker.check_getattr_method` in the mypy distribution.)
For the `__init__.py` "Cannot assign to a type" case, I propose to add "# type: ignore" after `ts = TransactionSet` to tell mypy to ignore that line. It is for backward compatibility, so I think ignoring it is okay.
Regarding `file.class`, my reading of https://docs.python.org/3/reference/lexical_analysis.html#keywords is that that attribute name really is illegal and should be changed. Thoughts?
That leaves the methods in `TransactionSet` with the same name as but different signatures than methods in the superclass, `ts`. This really is wrong. If you have an object of type `ts` and call its `hdrFromFdno` method, the type of the returned value depends on whether your object is just a `ts` or is really a member of the subclass `TransactionSet`. Fixing that properly means changing the method names in one class or the other, thereby breaking backwards compatibility. Do any known consumers use the `ts` class directly? If not, are you open to changing the `ts` method names? If so, then another approach is to break the superclass-subclass relationship. Make `TransactionSet` inherit from nothing, but contain a `ts` object to which it delegates. If that isn't acceptable, then I can sprinkle more "# type: ignore" comments around to paper over the issue, but that will hamper type checking of consumers.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/1615#issuecomment-812041166
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20210401/70f3201e/attachment.html>
More information about the Rpm-maint
mailing list