-
Notifications
You must be signed in to change notification settings - Fork 96
Consider type hints for 3.x.y release? #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm a huge fan of typing in Python. I wasn't aware about impact on performance but I think every library should use them. As far as I know, Python 3.4 is no longer maintained so we can drop support for it. I think it's a must-have feature for semver 3.0.0 :) |
Thanks Karol for your feedback! 👍 The performance depends probably on how difficult the types are and how big the library is. I've read somewhere an article about it. If I remember correctly, the performance penalty isn't big, but measurable. If we use that, I would suggest to add mypy as an additional check besides black/flake8/docstrings. |
I'm just acclimating myself to static typing now and To minimize the amount of overhead involved in this, it's worth noting there are several ways to get the typing info, among which are:
Anyway I'm really eager to see this added into |
@jwarner112 Many thanks Jeff for your motivating comment and your useful hints. 👍 Do you have any recommendations which of the two (semver-stubs or typeshed) are useful? I vaguely recall that a stubs package is easier to create than adding the information to typeshed. If I remember correctly, you have more control when creating a stubs package than adding your changes to typeshed (and waiting to be integrated). Probably my information is incomplete or inaccurate. If you have any hints or tips which could be helpful for this project, I would be very grateful for your help. |
I can't say for sure which is better, but I can definitely say that having your own Edit: As for the implementation of typing stubs themselves, I have absolutely no idea. If my work comes across it though and I have to figure it out, I'll remember to come back here and update. |
I'm having trouble finding evidence that type hints have any non-trivial runtime performance penalty. The best argument I can find is that importing the Adding to @jwarner112 's list of alternatives: you can also put type stubs in a separate Anecdotally, I find |
I've read it somewhere, but can't remember where I've found it. It wasn't much, but it was just a tiny overhead. ATM I'm working on the 3.0.0 release and I'm publishing the first alpha version soon. Maybe I can add the type hints in one of the next alphas or betas. |
I've created tomschr#6 with type hints directly in the code. Do you think I should move them to a |
I don't have much experience with type hints yet. From what I've seen, I think a |
The two main functional uses of
For python <3.5 support, you can also add type hints via inline Not sure which python versions you intend to support in semver 3. But strictly speaking, if you only want to support non-EOL python versions (>=3.6), you don't need a |
Thanks @sbrudenell for your input. 👍 We currently would like to support Python >=3.6. I was under the impression, the |
Well on pycharm, the inline types are parsed quite well, and it also tries its best to infer type of other parts in the code. I agree with @sbrudenell on the fact that having them inline makes the code more readable, so if you have a more basic editor that doesn't read any type hints, having to open the |
Ok, I had to edit my own comment. I have overlooked some of the comments. So it seems we don't need a |
As Thomas Laferriere already added type hints into #290, I think we can consider this as done now. |
Inline type hints LGTM. Just to clarify:
I probably caused too much confusion by bringing up |
Uh oh!
There was an error while loading. Please reload this page.
Situation
Python 3.5 introduced the
typing
module. As soon as we are sunsetting the 2.9.x release of semver, it raises the question if we should use type hints for our 3.x.y release of semver.Currently, we don't use it for our functions and methods.
To avoid any misinterpretations, the
typing
module contains this note:To start discussion and to get a better picture where we stand on this topic, I've opened this issue. 😉
Example
This is a short example of a type hint for the
parse
function:Bernát Gábor recommends that “type hints should be used whenever unit tests are worth writing.”
Pros and Cons
I've collected some pros and cons, probably there are more that I haven't listed here. This list is by no means exhaustive. Feel free to amend it.
Pros
sphinx-autodoc-typehints
plugin.Cons
mypy
).Scope
If we want this, it will only be implemented in the 3.x.y release of semver. Older releases (2.9.x) are not covered by this issue and won't be modified.
Furthermore, we need to create a
semver.pyi
file with the commandstubgen
(integrated in mypy).See also
The text was updated successfully, but these errors were encountered: