Skip to content

Conversation

@carlosmn
Copy link
Member

@carlosmn carlosmn commented Oct 6, 2014

The sequence interface, with len(X) returning 0 makes Python consider the object falsy, which is nonsensical. Always consider these to be True.

This fixes #432

@carlosmn carlosmn force-pushed the object-nonzero branch 2 times, most recently from e687c4a to 54d1f29 Compare October 6, 2014 12:36
@carlosmn
Copy link
Member Author

carlosmn commented Oct 6, 2014

Well, it looks like pypy3k still implements the Python 2 C API and now I'm sad. I've also no idea why CPython 3.4 thinks we returned an error.

The representation of Tree as a sequence causes boolean coercion to
consider the empty tree to be False, which is nonsensical.

Override __nonzero__ for all object types to return True.

This fixes libgit2#432.
Similarly to the previous commit, an Index is not False even if it
presents a sequence interface with a length of zero.
@jdavid
Copy link
Member

jdavid commented Oct 8, 2014

I am not going to start an argument on whether Python behaviour makes sense or not. But having an object which when evaluated has always the same constant value serves no purpose.

If we are going to override the default behaviour, it would be to raise an error, so to say we do not support implicit logical operations with these objects. But then, what are we trying to fix?

@carlosmn
Copy link
Member Author

The point of this isn't so much about python's behaviour, but our usage of len() vs what it seems to expect. We use it for the amount of entries or data content, but it doesn't mean that there is no other information of value there.

We still have the repository, path, whatever else of value. My point here is that an empty file isn't falsy and thus an empty index or blob shouldn't be either.

But if you think that the behaviour is fine, then that's just fine; feel free to close this.

@jdavid jdavid closed this Jan 16, 2015
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

Successfully merging this pull request may close these issues.

Repository.diff fails when treeish is "empty"

2 participants