#1 by Govert
It loops over the players, comparing their role to the given role. It uses 'if p.role() == role:' But role is a property (returning a string), and therefore not callable.
#2
by
Chris_oTree
As far as I can see it works OK.
If you define the constants like SENDER_ROLE , RECEIVER_ROLE, etc., then it will use the .role property.
def get_player_by_role(self, role):
if get_roles(self._Constants):
try:
return self.player_set.filter_by(_role=role).one()
except NoResultFound:
pass
else:
for p in self.get_players():
if p.role() == role:
return p
msg = f'No player with role "{role}"'
raise ValueError(msg)
.role() is only used for the old-style role definitions that were phased out several years ago.