- replies
- 1
- announces
- 0
- likes
- 3
@jmtd 🦆🦆🪿
@jmtd ((Billie Eilish's 'What Was I Made For' playing softly in the background))
@jmtd
The combination of duck typing and coercion is an amazing way to create very subtle bugs.
@jmtd it makes sense at the kernel level: a file path is a nice string that resolves to a file descriptor, which itself is an integer that the file system uses to get to the actual data. So that capability makes sense for low level processes.
So you hit one of Python's annoyances where despite being a high level language, some of the quirks of the underlying C API sometimes surface to wreck havoc on your code.
$ touch /tmp/nah
$ exec 3</tmp/nah
$ unlink /tmp/nah
$ python
>>> import os.path
>>> os.path.exists(3)
True
>>> os.readlink('/proc/self/fd/3')
'/tmp/nah (deleted)'
that’s messed up 🤯 I thought it would at least check if the file descriptor is still linked in the FS (st_nlink > 0)