8000 Repository.directory_contents throws AttributeError when path is a file · Issue #628 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

Repository.directory_contents throws AttributeError when path is a file #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AndyMan1 opened this issue Jul 15, 2016 · 0 comments
Closed

Comments

@AndyMan1
Copy link
AndyMan1 commented Jul 15, 2016

This is sort of the inverse of #627. I wasn't sure if I should combine the two issues or not.

Using Version 1.0.0a4, Repository.directory_contents throws an AttributeError when you mistakenly give it a path to a file rather than a directory. It looks like the code isn't expecting that to happen.

Given that contents() was split into directory_contents() and file_contents(), it would be nice if both could handle when they're used incorrectly and throw an appropriate error.

example:

>>> from github3 import login
>>> gh = login('<username>', password='<password>')
>>> repo = gh.repository('sigmavirus24', 'github3.py')
>>> repo.directory_contents('README.rst')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/andy.husak/.virtualenvs/repo_api/lib/python2.7/site-packages/github3/repos/repo.py", line 1130, in directory_contents
    return return_as((j.get('name'), Contents(j, self)) for j in json)
  File "/home/andy.husak/.virtualenvs/repo_api/lib/python2.7/site-packages/github3/repos/repo.py", line 1130, in <genexpr>
    return return_as((j.get('name'), Contents(j, self)) for j in json)
AttributeError: 'unicode' object has no attribute 'get'
itsmemattchung added a commit to itsmemattchung/github3.py that referenced this issue Jul 26, 2016
When the wrong data type is passed to the method, like a list or string,
an exception is returned.  Instead, we should be raising the exception.

I added a single unit test, which asserts that an error is raised.

Fixes sigmavirus24#628 and
sigmavirus24#627.
Sriharivignesh pushed a commit to Sriharivignesh/github3.py that referenced this issue Nov 18, 2017
When the wrong data type is passed to the method, like a list or string,
an exception is returned.  Instead, we should be raising the exception.

I added a single unit test, which asserts that an error is raised.

Fixes sigmavirus24#628 and
sigmavirus24#627.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0