Is it safe to swap a 30A "Dryer Socket" with a 40A "Range Socket" if the breaker is 40A?
It appears to me that this cable has two insulated conductors for the two hot legs plus an uninsulated conductor to be used as a ground, i.e., it does not have a third insulated cable to be used as a neutral. The cable is wired to the receptacle using the uninsulated conductor as a neutral. This is not allowed by code.
This cable can legally supply 240 V, not both 120 V and 240 V. It is not suitable for any appliance which requires both 120 and 240 V. What are the requirements of your new range?
Unless your new range is a special design which requires only 240 V, you must replace this cable all the way back to the panel or subpanel if there is one. Look at the installation instructions for the range. It should tell you whether it requires a neutral. If it does, then you will need a new (4 wire) cable.
You could use a 3-wire appliance cord and plug it into this receptacle and the range would work perfectly, but if the range requires a neutral, then current will regularly be flowing in the uninsulated conductor. This is not allowed by code.
If the cable had 3 inslated conductors, you could use it as is or you could retrofit a ground, but you cannot retrofit a neutral.