Your doubts are incorrect. There's a fairly standard way of extracting the file type out of files on linux, which relies on a mix of extensions and magic bytes. Here's where you can start to read about this:
I'm a little surprised that that link doesn't go to libmagic[1]. No doubt XDG_MIME is an important spec for desktop file detection, but I think libmagic and the magic database that underpins it are more fundamental to filetype detection in general.
It's also one of my favorite oddities on Linux. If you're a Windows user the idea of a database of signatures for filetypes that exists outside the application that "owns" a file type is novel and weird.
libmagic maintains its own separate database from xdg. XDG db is meant from the ground up to have other apps add to it etc… so that one is the one apps use as a library usually, if they want to integrate nicely and correctly with other installed apps. libmagic is the hacking of the two :)
mostly for executable files.
I doubt many Linux apps look inside a .py file to see if it's actually a JPEG they should build a thumbnail for.