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

Increase the usage of augmented assignment statements #206

Open
elfring opened this issue Nov 2, 2021 · 1 comment
Open

Increase the usage of augmented assignment statements #206

elfring opened this issue Nov 2, 2021 · 1 comment

Comments

@elfring
Copy link

elfring commented Nov 2, 2021

👀 Some source code analysis tools can help to find opportunities for improving software components.
💭 I propose to increase the usage of augmented assignment statements accordingly.

diff --git a/pslab/external/MF522.py b/pslab/external/MF522.py
index 1b30454..8c25bc4 100644
--- a/pslab/external/MF522.py
+++ b/pslab/external/MF522.py
@@ -250,7 +250,7 @@ class MF522:
         i = 2000
         while True:
             n = self.read(self.ComIrqReg)
-            i = i - 1
+            i -= 1
             if ~((i != 0) and ~(n & 0x01) and ~(n & waitIRq)):
                 break
 
@@ -279,7 +279,7 @@ class MF522:
                     i = 0
                     while i < n:
                         returnedData.append(self.read(self.FIFODataReg))
-                        i = i + 1;
+                        i += 1;
             else:
                 status = self.MI_ERR
         return (status, returnedData, backLen)
@@ -315,8 +315,8 @@ class MF522:
             i = 0
             if len(returnedData) == 5:
                 while i < 4:
-                    serNumCheck = serNumCheck ^ returnedData[i]
-                    i = i + 1
+                    serNumCheck ^= returnedData[i]
+                    i += 1
                 if serNumCheck != returnedData[i]:
                     status = self.MI_ERR
             else:
@@ -347,7 +347,7 @@ class MF522:
         i = 0
         while i < 5:
             buf.append(serNum[i])
-            i = i + 1
+            i += 1
         pOut = self.CalulateCRC(buf)
         buf.append(pOut[0])
         buf.append(pOut[1])
@@ -368,13 +368,13 @@ class MF522:
         i = 0
         while (i < len(Sectorkey)):
             buff.append(Sectorkey[i])
-            i = i + 1
+            i += 1
         i = 0
 
         # Next we append the first 4 bytes of the UID
         while (i < 4):
             buff.append(serNum[i])
-            i = i + 1
+            i += 1
 
         # Now we start the authentication itself
         (status, returnedData, backLen) = self.MFRC522_ToCard(self.PCD_MFAuthent, buff)
@@ -422,7 +422,7 @@ class MF522:
             buf = []
             while i < 16:
                 buf.append(writeData[i])
-                i = i + 1
+                i += 1
             crc = self.CalulateCRC(buf)
             buf.append(crc[0])
             buf.append(crc[1])
@@ -441,7 +441,7 @@ class MF522:
                 self.MFRC522_Read(i)
             else:
                 print("Authentication error")
-            i = i + 1
+            i += 1
 
 
 if __name__ == "__main__":
@bessman
Copy link
Collaborator

bessman commented Nov 2, 2021

Sure, that's a good idea. However, this particular module (MF522) is most likely broken since no active developer has access to that sensor. We can only accept a pull request with this kind of improvement if it also fixed the module itself.

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