Skip to content
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

Problems with type hints in python < 3.8 #128

Closed
postlund opened this issue Jun 12, 2021 · 4 comments
Closed

Problems with type hints in python < 3.8 #128

postlund opened this issue Jun 12, 2021 · 4 comments

Comments

@postlund
Copy link

When dependabot tries to bump bitarray to the latest version in my project, typing fails for python 3.6 and python 3.7 with this error:

.tox/typing/lib/python3.7/site-packages/bitarray/__init__.pyi:15: error: invalid syntax

Looking at that line:

def __init__(self, code: Codedict, /) -> None: ...

I would expect it's the / (end of positional arguments) that is the culprit. AFAIK it was added in python 3.8. This kinda causes problems with earlier versions of python, as type checking cannot be performed there because of this. I know too little about stub files to know if it's possible to work around this, but I would be glad if it could be fixed. Any idea if it's possible?

@ilanschnell
Copy link
Owner

Thanks for using bitarray and reporting this issue. Yes. positional only arguments have been added in Python 3.8, and I can simply remove those from the sub files in order to make it better compatible with older Python version. Bitarray itself supports Python 2.7, 3.5 .. 3.10. I've only added typing information in those stub files in the 2.1.1 release, and since those files are separate, they will not be executed unless one runs a type checker. Hence, I only tested the stub files for Python 3.9. However, with a little extra work it should be possible to support typing for all Python 3 versions which bitarray supports.

@postlund
Copy link
Author

Yeah, I noticed from the classifiers that "most" versions of python are supported and concluded that it was likely just an issue with the type hints 😊 I would love it if you could remove the positional argument checks, that would help me a lot. I've put a restriction in my dependencies for the latest version for now as all my CI jobs started to fail, so no hurry on my end. But a fix would be very appreciated 👍

The GitHub action for python supports most versions, maybe you should add an automatic workflow that verifies each PR?

@ilanschnell
Copy link
Owner

I just released bitarray 2.1.2 which now supports type hinting for all Python 3 versions which bitarray supports (that is, Python 3.5 and higher).

Please feel free to reopen this issue, or create a new one if you should run into any problems. Thanks again

@postlund
Copy link
Author

Dependabot bumped it right it, so must have worked fine. Thanks for the swift handling of this! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants