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

pyOpenSSL: Adapt to changes in 22.0.0 #7080

Merged
merged 4 commits into from
Jan 29, 2022
Merged

pyOpenSSL: Adapt to changes in 22.0.0 #7080

merged 4 commits into from
Jan 29, 2022

Conversation

lovetox
Copy link
Contributor

@lovetox lovetox commented Jan 29, 2022

  • Fix digest argument type, these methods only accept str
    The docstrings were fixed for some of these methods in pyca/pyopenssl@41ceefb

  • pyOpenSSL dropped python2 compatibility with 22.0.0

  • Replace Text alias with str

  • Don’t inherit from object

These methods only accept str

The docstrings were fixed for some of these methods in pyca/pyopenssl@41ceefb
@lovetox lovetox changed the title Fix digest type pyOpenSSL: Adapt to changes in 22.0.0 Jan 29, 2022
@lovetox lovetox force-pushed the master branch 2 times, most recently from 9f3a029 to 784d613 Compare January 29, 2022 21:02
- pyOpenSSL dropped python2 compatibility with 22.0.0
- Replace Text alias with str
- Don’t inherit from object
Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall! A few nits.

@@ -129,7 +129,7 @@ class X509Store:
def __init__(self) -> None: ...
def add_cert(self, cert: X509) -> None: ...
def add_crl(self, crl: CRL) -> None: ...
def load_locations(self, cafile: Text | bytes, capath: Text | bytes | None = ...) -> None: ...
def load_locations(self, cafile: str | bytes, capath: str | bytes | None = ...) -> None: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cafile and capath should be annotated with _typeshed.StrOrBytesPath. They get passed to _path_bytes which calls os.fspath.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the suggestions

def load_crl(type: int, buffer: str | bytes) -> CRL: ...
def load_pkcs7_data(type: int, buffer: str | bytes) -> PKCS7: ...
def load_pkcs12(buffer: str | bytes, passphrase: bytes | None = ...) -> PKCS12: ...
def sign(pkey: PKey, data: str | bytes, digest: str) -> bytes: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea for future PR: Some arguments, such as data here, get passed to text_to_bytes_and_warn, which emits a DeprecationWarning if you pass a string. We should probably just change them to bytes in typeshed, so that the warning happens when type checking rather than at runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im curious, is this a standard thing done in the typing community?

This seems to force application maintainers into one of the following options if they use a deprecated type

  • They could add a # type: ignore which stops typing of more stuff than we want
  • They could not update to the newest version of these stubs and miss out on changes which fixed wrong typings
  • They could use the new type, which may or may not be possible depending on the project

Don’t seem very good options to me

Especially because DeprecationWarnings can be catched by unittests.

But i don’t have much experience with typing so maybe this is standard procedure in the community and its not a big deal.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently don't have a good way to mark deprecated things. There's some discussion about this here: python/typing#1043

For now, we usually keep deprecated things in the spirit of avoiding false positives. This was just a random idea.

@Akuli
Copy link
Collaborator

Akuli commented Jan 29, 2022

After a review, please don't --amend or force-push, as it makes it more difficult for reviewers to see what changed since the review. We will use GitHub's "Squash and merge" button, which combines the whole PR into a single commit anyway.

Copy link
Collaborator

@Akuli Akuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Akuli Akuli merged commit 9aeecb4 into python:master Jan 29, 2022
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

Successfully merging this pull request may close these issues.

2 participants