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

Use well-defined enum representation #6042

Merged
merged 1 commit into from
May 12, 2021
Merged

Use well-defined enum representation #6042

merged 1 commit into from
May 12, 2021

Conversation

tiran
Copy link
Contributor

@tiran tiran commented May 10, 2021

Python 3.10 changed enum's object and string representation. PyCA
cryptography now uses a custom subclass of enum.Enum() will well-defined
__repr__ and __str__ from Python 3.9.

Related: https://bugs.python.org/issue40066
Fixes: #5995
Signed-off-by: Christian Heimes [email protected]

@tiran tiran force-pushed the enum_repr branch 4 times, most recently from a568d8b to 85b51e0 Compare May 10, 2021 12:17
Copy link
Member

@alex alex left a comment

Choose a reason for hiding this comment

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

The motivation here is that __repr__ changed in 3.10 and we have tests on that, right?

@reaperhulk opinions on doing this vs. just putting a branch in the tests?

@@ -30,6 +30,7 @@ jobs:
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.1.5"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.2.5"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.3.2"}}
- {VERSION: "3.10-dev", TOXENV: "py310", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1k"}}
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need an openssl type, it can just use the default one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So just {VERSION: "3.10-dev", TOXENV: "py310"}?

@alex
Copy link
Member

alex commented May 10, 2021 via email

@tiran
Copy link
Contributor Author

tiran commented May 10, 2021

Correct, the object and string representation were changed during the alphas. IIRC it changed again between last alpha and first beta. PyCA's tests contain checks for representation of some objects, for example:

___________________________ TestTLSFeature.test_repr ___________________________

self = <tests.x509.test_x509_ext.TestTLSFeature object at 0x7faf75790d60>

    def test_repr(self):
        ext1 = x509.TLSFeature([x509.TLSFeatureType.status_request])
>       assert repr(ext1) == (
            "<TLSFeature(features=[<TLSFeatureType.status_request: 5>])>"
        )
E       AssertionError: assert '<TLSFeature(...us_request])>' == '<TLSFeature(...equest: 5>])>'
E         - <TLSFeature(features=[<TLSFeatureType.status_request: 5>])>
E         ?                       -                             ----
E         + <TLSFeature(features=[TLSFeatureType.status_request])>

tests/x509/test_x509_ext.py:150: AssertionError

Miro asked me to look into the matter to unblock Python 3.10 update for next Fedora release. https://bugzilla.redhat.com/show_bug.cgi?id=1952522

Python 3.10 changed enum's object and string representation. PyCA
cryptography now uses a custom subclass of enum.Enum() will well-defined
__repr__ and __str__ from Python 3.9.

Related: https://bugs.python.org/issue40066
Fixes: pyca#5995
Signed-off-by: Christian Heimes <[email protected]>
@reaperhulk
Copy link
Member

I think I'm in favor of implementing __repr__ since we can't guarantee stability without that. Alternately, we could stop testing repr, but since we want it to be readable we should commit to a stable one.

@alex alex merged commit 1b922ed into pyca:main May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

tests are failing with Python 3.10.0a7 due to change in repr()
3 participants