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

refactor(admissions): do not unpack tuples in hash calculation for admissions extension types #11909

Merged

Conversation

hoefling
Copy link
Contributor

@hoefling hoefling commented Nov 6, 2024

This is a small improvement for the hash magic methods of the types added for the Admissions extension in #11875. I didn't pay enough attention when doing the initial implementation and overlooked an example of the policy_qualifiers field in PolicyInformation type:

def __hash__(self) -> int:
if self.policy_qualifiers is not None:
pq: tuple[str | UserNotice, ...] | None = tuple(
self.policy_qualifiers
)
else:
pq = None
return hash((self.policy_identifier, pq))

I amended the methods ProfessionInfo.__hash__(), Admission.__hash__() and Admissions.__hash__() to avoid tuple unpacking and adjusted the none check for profession_oids to have the same logic as the one for the policy_qualifiers. I also removed the type hint from the pq local variable since mypy can infer the types starting with v1.11 (IIRC).

…ension types

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
@alex alex enabled auto-merge (squash) November 6, 2024 23:56
@alex alex merged commit 530d667 into pyca:main Nov 7, 2024
60 checks passed
@hoefling hoefling deleted the refactor/extension/admissions/hash-magic-methods branch November 7, 2024 00:03
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.

2 participants