%q was implemented for that reason according to the discussion from january to march 2006 with subject "sprintf %O"
checking today, i notice that %q does only handle strings. this is not what i would have expected. to work as intended %q would need to handle any type, just like %O does.
greetings, martin.