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

paramiko stubs seem incorrect for python3 #5736

Closed
mrodden opened this issue Jul 7, 2021 · 5 comments · Fixed by #10109
Closed

paramiko stubs seem incorrect for python3 #5736

mrodden opened this issue Jul 7, 2021 · 5 comments · Fixed by #10109
Labels
help wanted An actionable problem of low to medium complexity where a PR would be very welcome

Comments

@mrodden
Copy link

mrodden commented Jul 7, 2021

I am getting a bunch of errors from mypy with the types-paramiko package.

Some are imports that are not in the stubs for paramiko like paramiko.PublicBlob which is an alias import from paramiko.pkey.PublicBlob (see https://github.com/paramiko/paramiko/blob/master/paramiko/__init__.py#L65)

Others seem to be issues between python2 and python3 where many of the object stubs are declaring type str when in fact paramiko is treating it like a bytes (see https://github.com/python/typeshed/blob/master/stubs/paramiko/paramiko/pkey.pyi#L36 and https://github.com/paramiko/paramiko/blob/master/paramiko/pkey.py#L679-L681)

I'm not sure if there is a nice way to resolve this, as it is obviously an str in py2 but bytes in py3.

I have currently chosen to ignore the types-paramiko package in my project, as it causes too many false check errors with mypy.

@Akuli
Copy link
Collaborator

Akuli commented Jul 7, 2021

str in py2 but bytes in py3

In this case, you should just use bytes. In Python 2, str and bytes are the same, and unicode is different.

@mrodden
Copy link
Author

mrodden commented Jul 7, 2021

The issue can be highlight with the following

pub_blob = paramiko.pkey.PublicBlob.from_file("/path/to/file")
rsa_key = paramiko.pkey.RSAKey(data=pub_blob.key_blob)

The second line causes a mypy arg-type issue, since the stubs say that key_blob is a str and the data kwarg to RSAKey.__init__ is a bytes.

The key_blob IS a bytes though, so it works fine at runtime.

@mrm-david
Copy link

Another example : in exec_command the parameter command is str in the stubs; but it can actually accept byte as well since it eventually gets passed to b()which converts it to byte unless it was already byte, in which cases it returns it untouched.

@Akuli
Copy link
Collaborator

Akuli commented Aug 10, 2022

PRs to improve the stubs are welcome :)

@AlexWaygood AlexWaygood added the help wanted An actionable problem of low to medium complexity where a PR would be very welcome label Aug 27, 2022
@JelleZijlstra
Copy link
Member

In #10109 I fix two of the specific issues mentioned above. Anything else is best handled in a focused issue/PR that describes exactly what type is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted An actionable problem of low to medium complexity where a PR would be very welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants