I would not recommend assuming 40mA per pin. It is only guaranteed that the chip will not be damaged with up to 40mA, it is NOT guaranteed that it will work properly.
Think of a maximum of 20mA per pin in your design. This is the operating value according to the data sheet