8000 how to check if no resource was found? · Issue #665 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

how to check if no resource was found? #665

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
rmamba opened this issue Jan 4, 2017 · 1 comment
Closed

how to check if no resource was found? #665

rmamba opened this issue Jan 4, 2017 · 1 comment

Comments

@rmamba
Copy link
rmamba commented Jan 4, 2017

How do I check if github3 does not find resource?

for example:

import github3
g = github3.GitHub(token='mytoken')
i1 = g.issue('rmamba', 'sss3', 1) #exists, returns Issue
i2 = g.issue('rmamba', 'sss3', 1000) #does not exists, return NullObject

how do I do this:

if i is None:
  handle none

I can do if i2 is i2.Empty. But then with i1 it does not work because it returns valid issue and i1.Empty does not exist. I tried with NullObject but it always says it's false.

i1 is NullObject #false
i1 is NullObject('Issue') #false

so I had to do this for now:

if '%s' % i2 == '':
  handle None

because it works for both NullObjects and valid results returned

@sigmavirus24
Copy link
Owner

Sorry for the delay in getting back to you.

In your example you can very simply do

if i1:
    # Do things because it exists

if i2:
    # Do things because it exists

The NullObject is implemented to behave as a false-y value just like None, '', False, 0, [], {}, etc.

Empty which I suspect you do not have is meant for attributes. That said, both of these may be going away for 1.0: #670

Your input would be very welcome.

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