Commits

Ian Cordasco committed 0749609

Start adding __str__ methods where logical

For example, if you want to do

u = github3.user(username)
r = github3.repository(u, reponame)

This should work now work. I'm looking for other areas to add this
functionality.

Comments (0)

Files changed (3)

github3/models.py

         """Builds a new API url from scratch."""
         parts = [kwargs.get('base_url') or self._github_url]
         parts.extend(args)
+        parts = [str(p) for p in parts]
         key = tuple(parts)
         if not key in __url_cache__:
             __url_cache__[key] = '/'.join(parts)
         self.master_branch = repo.get('master_branch', '')
 
     def __repr__(self):
-        return '<Repository [{0}/{1}]>'.format(self.owner.login, self.name)
+        return '<Repository [{0}]>'.format(self)
+
+    def __str__(self):
+        return '{0}/{1}'.format(self.owner, self.name)
 
     def _update_(self, repo):
         self.__init__(repo, self._session)
     def __repr__(self):
         return '<Content [{0}]>'.format(self.path)
 
+    def __str__(self):
+        return self.decoded
+
     @property
     def git_url(self):
         """API URL for this blob"""
         self.commit = tag.get('commit', {})
 
     def __repr__(self):
-        return '<Repository Tag [{0}]>'.format(self.name)
+        return '<Repository Tag [{0}]>'.format(self)
+
+    def __str__(self):
+        return self.name
 
 
 class RepoComment(BaseComment):
     def __repr__(self):
         return '<User Key [{0}]>'.format(self.title)
 
+    def __str__(self):
+        return self.key
+
     def _update_(self, key):
         self.__init__(key, self._session)
 
     def __repr__(self):
         return '<Plan [{0}]>'.format(self.name)  # (No coverage)
 
+    def __str__(self):
+        return self.name
+
     def is_free(self):
         """Checks if this is a free plan.
 
     def __repr__(self):
         return '<User [{0}:{1}]>'.format(self.login, self.name)
 
+    def __str__(self):
+        return self.login
+
     def _update_(self, user):
         self.__init__(user, self._session)