I think it just returns whatever the underlying gethostname() call does. For example (though this is on Linux):
# hostname foobar
# python -c 'import socket; print(socket.gethostname()) '
foobar
# hostname foobar.example.org
# python -c 'import socket; print(socket.gethostname()) '
foobar.example.org
If you just want the hostname part, it's not hard to remove the rest:
# python -c 'import socket; import re; print(re.sub("\..*", "", socket.gethostname()))'
foobar