
On Wed, 1 Dec 2021 at 12:12, Sebastian Rittau <srittau@rittau.biz> wrote:
Am 30.11.21 um 13:39 schrieb Oscar Benjamin:
Others have mentioned the pressure on libraries to adopt typing and I've certainly noticed this with SymPy. I think type hints could be good for SymPy for internal use but it seems that a lot of users want it for external reasons that I don't always understand but that also seems to come partly from editors as well.
Please note that users of you library usually won't care that the library uses type hints. It's more important that there are type hints for the API, which can also be supplied using a stub file.
The distinction between internal code and API is not always that clear in SymPy but in any case it is still very hard to type many of SymPy's public API functions. You are right that there is a distinction here because when I imagine that type hints could be useful for SymPy I think of adding hints in places that users definitely don't care about. Adding hints for public API is more immediately useful for users but also much harder because many public APIs are quite liberal/flexible in what they accept and return.
Some people apparently want to add type hints that look completely useless to me like def f() -> Union[MyClass, Any] As I understand it this does not give any meaningful information to a type checker but it apparently makes vscode work better: https://github.com/sympy/sympy/pull/22180#discussion_r718917577
We have several resources that can help with questions like these:
https://github.com/python/typing/discussions is a forum for questions about typing. The forum also has a separate section where users can ask for reviews of type annotations, for example in stub files. https://gitter.im/python/typing is a chat for typing-related questions. We are also working on a documentation hub at https://typing.readthedocs.io/, but there is not much to see at the moment.
I'm not sure what your point is here. Are you suggesting that I use these forums or that I redirect other people there?
There are other open "issues" like this for SymPy where the presumption is that not having type hints is now to be considered a deficiency of the library regardless of whether the hints have any benefit for internal use. I don't object to adding the hints but it's a huge amount of work that someone would have to do and I don't want to add useless/inaccurate hints temporarily (as some have suggested to do).
Please note that users of you library usually won't care that the library uses type hints. It's more important that there are type hints for the API, which can also be supplied using a stub file. This is usually quite a bit easier than typing an existing code base. Alternatively, just adding type annotations to the public API, but not using type checking yourself, can be useful for your users.
My previous statement still stands: it's a huge amount of work and I do not want to add bogus hints as a stopgap. If the hints are to be added then someone needs to do that hard work to make sure that they are accurate. -- Oscar