I think you can just test `'q' in opts` rather than calling hasattr.