88# Python Imports
99# Collections
1010from collections import defaultdict
11- # Contextlib
12- from contextlib import suppress
1311# Inspect
1412from inspect import signature
1513# WeakRef
@@ -227,15 +225,19 @@ def __getattr__(self, attr):
227225 raise AttributeError ('Attribute "{0}" not found' .format (attr ))
228226
229227 # Is the attribute a property descriptor?
230- with suppress ( AttributeError ) :
228+ try :
231229 value = value .__get__ (instance )
230+ except AttributeError :
231+ pass
232232
233233 # Is the value a dynamic function?
234234 if isinstance (value , (MemberFunction , InputFunction )):
235235
236236 # Cache the value
237- with suppress ( AttributeError ) :
237+ try :
238238 object .__setattr__ (self , attr , value )
239+ except AttributeError :
240+ pass
239241
240242 return value
241243
@@ -253,7 +255,8 @@ def __setattr__(self, attr, value):
253255
254256 # Try to resolve a dynamic attribute
255257 try :
256- self , setter = self .dynamic_attributes [attr ].__set__
258+ self , setter = self .dynamic_attributes [attr ]
259+ setter = setter .__set__
257260
258261 # KeyError:
259262 # The attribute does not exist.
@@ -334,7 +337,7 @@ def server_classes(self):
334337
335338 @cached_property
336339 def dynamic_attributes (self ):
337- """Returns the dynamic attributes for this entities ."""
340+ """Returns the dynamic attributes for this entity ."""
338341 attributes = {}
339342 for cls , instance in self .server_classes .items ():
340343 attributes .update (
@@ -701,34 +704,44 @@ def take_damage(
701704 if attacker_index is not None :
702705
703706 # Try to get the Entity instance of the attacker
704- with suppress ( ValueError ) :
707+ try :
705708 attacker = Entity (attacker_index )
709+ except ValueError :
710+ pass
706711
707712 # Was a weapon given?
708713 if weapon_index is not None :
709714
710715 # Try to get the Weapon instance of the weapon
711- with suppress ( ValueError ) :
716+ try :
712717 weapon = Weapon (weapon_index )
718+ except ValueError :
719+ pass
713720
714721 # Is there a weapon but no attacker?
715722 if attacker is None and weapon is not None :
716723
717724 # Try to get the attacker based off of the weapon's owner
718- with suppress ( ValueError , OverflowError ) :
725+ try :
719726 attacker_index = index_from_inthandle (weapon .owner_handle )
720727 attacker = Entity (attacker_index )
728+ except (ValueError , OverflowError ):
729+ pass
721730
722731 # Is there an attacker but no weapon?
723732 if attacker is not None and weapon is None :
724733
725734 # Try to use the attacker's active weapon
726- with suppress ( AttributeError ) :
735+ try :
727736 weapon = attacker .active_weapon
737+ except AttributeError :
738+ pass
728739
729740 # Try to set the hitgroup
730- with suppress ( AttributeError ) :
741+ try :
731742 self .hitgroup = hitgroup
743+ except AttributeError :
744+ pass
732745
733746 # Get a TakeDamageInfo instance
734747 take_damage_info = TakeDamageInfo ()
@@ -817,8 +830,10 @@ def _on_networked_entity_deleted(index):
817830 for delay in _entity_delays .pop (index , ()):
818831
819832 # Cancel the delay...
820- with suppress ( ValueError ) :
833+ try :
821834 delay .cancel ()
835+ except ValueError :
836+ pass
822837
823838 # Loop through all repeats...
824839 for repeat in _entity_repeats .pop (index , ()):
0 commit comments