Skip to content

Commit

Permalink
fix: client.client_id cannot be set to taken value
Browse files Browse the repository at this point in the history
fixed the bug which allowed to set multiple client ids to the same value
  • Loading branch information
201st-Luka committed Aug 23, 2023
1 parent 0f9db74 commit df103f6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pyclasher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,17 @@ def client_id(self):

@client_id.setter
def client_id(self, new_id):
global client_id
if isinstance(new_id, str) and new_id.isdigit():
new_id = int(new_id)

if not isinstance(new_id, (int, str)):
raise TypeError(f"Expected types int, str got {type(new_id)} "
f"instead.")
for client in Client.__instances:
if client.client_id == new_id:
raise ValueError(f"`new_id` {new_id} has already been taken "
f"and must be different")
self._client_id = new_id
return

Expand Down

0 comments on commit df103f6

Please sign in to comment.