Force attribute value on potentially non-existent or locked PyNode
From the documentation link you provided:


  ‘force’ kwarg, which causes the attribute to be added if it does not exist.


So the force kwargs does not seem to allow you to set a new dataType.

Hence it seems that the only way to set a new dataType is to remove and recreate the attribute. From this case, it seems hard to further simplify your code.