instead of if else  how about this if self ca file kwargs  cert reqs ssl cert required ca certs self ca file else kwargs  cert reqs ssl cert none self sock ssl wrap socket sock  self key file  self cert file kwargs 