Maybe (hopefully) batteries will get better, but I wouldn't go dumping my money into electric locomotive startups just yet.
Similar to the battery-equipped dual-mode trolleybuses increasingly getting developed / deployed[0] allowing both point-charging at stops and more independence from overhead line (so trolleys can more easily be rerouted, or can serve increasingly longer sections without overhead lines).
[0] they've existed since the 30s but mostly electric / ICE
I think someone else brought up that with electrification you could also put traction motors in rail cars like is done often with commuter rail systems. And there is actually no need for the battery to be part of the locomotive either. Think old steam trains with a coal car.
I don't want that thing anywhere near a train... Or where I live.
The result you can use overhead lines where safe, cheap and convenient and avoid them where they are not, like rail switching yards.
https://www.railjournal.com/regions/north-america/bnsf-and-g...