-
Notifications
You must be signed in to change notification settings - Fork 42
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
Type stubs #118
Comments
I can't say there has been any plan to create stubs at this point. Is there a specific benefit to generating and maintaining external type stubs for a pure python library? Would it not be easier to maintain if they were inline and used the comment approach as opposed to the py3 approach? We could also just hold off and make this a feature that uses proper type hints when we cut off the py2 support entirely. What are your thoughts on the need for external stubs for a pure python library, vs the cost of maintaining them to make sure they stay aligned? |
Since the library targets Python 2.7 as well as Python 3.x providing type stubs is a benefit since you can't directly add type hints in the code. Using comments is a legacy way to type a library as described here: https://realpython.com/lessons/type-comments/
The best solution is of course to drop Python 2.7 support and fully type the library with Python 3 type hints without having to maintain .pyi stubs. |
I would say that for a pure python library (vs a compiled extension), maintaining external type hints feels excessive. So I am inclined to go with either the legacy type comments (which I have used successfully in other py2/3 projects) or as part a new major version release that drops py2 entirely. |
Drop py2 support: #119 |
Hi again, For a future addition to the library I am reporting that I am getting the following error with MyPy when importing fileseq: # main.py
import fileseq
This is the PEP section about the |
I can work on dropping py2 support this weekend. And we can add the marker file. |
@justinfx So cool, thanks for taking time on this! If you need any help let me know |
@justinfx thank you this is much much better! I don't know which type checker you use, but if I check with MyPy, I get:
Then it depends if you want to type the whole library, including every function arguments and return types, what do you think? |
I don't use MyPy. Just the standard checker/linter integrated into Jetbrains. I've never used MyPy so I am not sure if it is far more aggressive. If enabling this py.typed feature is going to require adhering to MyPy standards then I'm probably going to remove it, as it isn't worth the effort right now. Otherwise I would need to add MyPy to the CI actions to ensure the code always passes the type checker. Should we just remove the py.typed marker? |
I've just pushed another commit that addresses all the errors reported by MyPy: 86b078a Does that look right to you at this point? I would need to add a |
@justinfx Adding the For example in VSCode I use Pylance + Pyright for the type checking in strict mode which works well. On the other hand, MyPy is open-source and is widely used in well established Python libraries. As for your last commit, it works like a charm! MyPy found no issues in the source files which is great. You can add MyPy as a CI check as well but it might require a little bit more setup if you have time for that 👍 |
I've added mypy type checking to the CI and merged to the v2 branch, which is being prepared to drop python2 support: |
@justinfx awesome, thank you! |
Hi @justinfx do you have an idea when this will be released? Are you waiting for other bug fixes to be solved for the v2? |
@johhnry i was waiting on one more v2 issue but I'm likely going to close it as a won't-fix. Might be able to release v2 within a day or two |
@johhnry I've released v2.0.0 |
@justinfx thanks for the quick release! One thing I noticed is that I get this error with Mypy (and Pylance in VSCode): # main.py
from fileseq import FileSequence
seq = FileSequence("test")
An easy fix is to do For example there's an issue on Dacite about this: konradhalas/dacite#133 As for the type hints themselves, your Mypy configuration was a bit too loose and the following functions that I am using don't have a proper type signature:
A more strict Mypy configuration is explained in details here: https://justincaustin.com/blog/mypy-tips-and-tricks/ What do you think? |
@johhnry please submit a PR. Like I said, I don't use MyPy, and I kind of did this on request and tried to check it with your setup. |
@justinfx I understand, I'll do a PR then. Thanks again for your time! |
Was that PR ever made? I am still getting the following mypy errors in fileseq:
|
@dkbarn no the PR hasn't been submitted as of yet |
@dkbarn as part of another fix, I have updated the type annotations to pass the strict |
Hi,
Are there any plans to provide type stubs for the library? (.pyi files not type hinting the code itself)
With the progress of type checkers such as MyPy, it would be nice to use it with Fileseq. See: https://typing.readthedocs.io/en/latest/source/stubs.html
If nobody is working on it I might do a merge request!
The text was updated successfully, but these errors were encountered: