pathlib / operator throws away the left side when right side is absolute
Small one that surprised me. Path('/data') / '/raw/file.csv' gives PosixPath('/raw/file.csv') — the first part is completely discarded. I expected /data/raw/file.csv. Python 3.11. Is this documented behavior? I couldn't find it in the pathlib docs and it caused a real bug where our app read from the wrong directory. My inputs come from a config where absolute-looking paths sometimes show up unexpectedly. We chose to reject at config-load time, which surfaced a bad value nobody had noticed.
4 replies