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

Question about function IBAN._validate_iban_checksum() #243

Open
neimad1985 opened this issue Feb 4, 2025 · 2 comments
Open

Question about function IBAN._validate_iban_checksum() #243

neimad1985 opened this issue Feb 4, 2025 · 2 comments

Comments

@neimad1985
Copy link

Hello :)

Quick question please.
In the code of function IBAN._validate_iban_checksum(), located at this permalink:

def _validate_iban_checksum(self) -> None:

I am wondering about the if condition:

if self.numeric % 97 != 1 or not checksum_algo.validate([self.bban, self.country_code], self.checksum_digits):

Aren't the two parts self.numeric % 97 != 1 and checksum_algo.validate([self.bban, self.country_code], self.checksum_digits) doing exactly the same check ?

The only difference I see is that for the first condition, many random types of iban generation could lead to obtaining one with 1 as the remainder of modulo 97, whereas in the second condition we explicitly check that the remainder was obtained with the proper iso7064 calculation method.
Am I right ? Would it be correct to keep only the second part of the if condition and get rid of the first part ? Or am I missing something ?

Thanks

@Natim
Copy link
Contributor

Natim commented Feb 5, 2025

I remember asking myself the same question, I believe if you try to remove it and run the test you will hit the case where it is needed.

@neimad1985
Copy link
Author

I just run the full test suite as is: all green.
Then I removed the first condition: all green.
Then I put back the first condition and remove the second one: all green.
I didn't hit the case you were guessing about.
Any other insight on this ?
Not that this is very important actually, it's just for my comprehension of the code.
I felt that the two conditions were redundant and wanted to make sure whether I was right or wrong.

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