Oid: Deprecate 'hex' in favour of str() or unicode()
Python has built-in functions to get a string representation of an object id, so let's use that instead of using a custom attribute.
This commit is contained in:
14
src/oid.c
14
src/oid.c
@@ -257,6 +257,11 @@ Oid_richcompare(PyObject *o1, PyObject *o2, int op)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
Oid__str__(Oid *self)
|
||||||
|
{
|
||||||
|
return git_oid_to_py_str(&self->oid);
|
||||||
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(Oid_raw__doc__, "Raw oid, a 20 bytes string.");
|
PyDoc_STRVAR(Oid_raw__doc__, "Raw oid, a 20 bytes string.");
|
||||||
|
|
||||||
@@ -267,12 +272,13 @@ Oid_raw__get__(Oid *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(Oid_hex__doc__, "Hex oid, a 40 chars long string (type str).");
|
PyDoc_STRVAR(Oid_hex__doc__, "Hex oid, a 40 chars long string (type str).\n"
|
||||||
|
"This attribute is deprecated, please use the built-int str() or unicode()\n");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Oid_hex__get__(Oid *self)
|
Oid_hex__get__(Oid *self)
|
||||||
{
|
{
|
||||||
return git_oid_to_py_str(&self->oid);
|
return Oid__str__(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyGetSetDef Oid_getseters[] = {
|
PyGetSetDef Oid_getseters[] = {
|
||||||
@@ -293,13 +299,13 @@ PyTypeObject OidType = {
|
|||||||
0, /* tp_getattr */
|
0, /* tp_getattr */
|
||||||
0, /* tp_setattr */
|
0, /* tp_setattr */
|
||||||
0, /* tp_compare */
|
0, /* tp_compare */
|
||||||
0, /* tp_repr */
|
(reprfunc)Oid__str__, /* tp_repr */
|
||||||
0, /* tp_as_number */
|
0, /* tp_as_number */
|
||||||
0, /* tp_as_sequence */
|
0, /* tp_as_sequence */
|
||||||
0, /* tp_as_mapping */
|
0, /* tp_as_mapping */
|
||||||
(hashfunc)Oid_hash, /* tp_hash */
|
(hashfunc)Oid_hash, /* tp_hash */
|
||||||
0, /* tp_call */
|
0, /* tp_call */
|
||||||
0, /* tp_str */
|
(reprfunc)Oid__str__, /* tp_str */
|
||||||
0, /* tp_getattro */
|
0, /* tp_getattro */
|
||||||
0, /* tp_setattro */
|
0, /* tp_setattro */
|
||||||
0, /* tp_as_buffer */
|
0, /* tp_as_buffer */
|
||||||
|
@@ -50,19 +50,19 @@ class OidTest(utils.BareRepoTestCase):
|
|||||||
def test_raw(self):
|
def test_raw(self):
|
||||||
oid = Oid(raw=RAW)
|
oid = Oid(raw=RAW)
|
||||||
self.assertEqual(oid.raw, RAW)
|
self.assertEqual(oid.raw, RAW)
|
||||||
self.assertEqual(oid.hex, HEX)
|
self.assertEqual(str(oid), HEX)
|
||||||
|
|
||||||
def test_hex(self):
|
def test_hex(self):
|
||||||
oid = Oid(hex=HEX)
|
oid = Oid(hex=HEX)
|
||||||
self.assertEqual(oid.raw, RAW)
|
self.assertEqual(oid.raw, RAW)
|
||||||
self.assertEqual(oid.hex, HEX)
|
self.assertEqual(str(oid), HEX)
|
||||||
|
|
||||||
def test_hex_bytes(self):
|
def test_hex_bytes(self):
|
||||||
if version_info[0] == 2:
|
if version_info[0] == 2:
|
||||||
hex = bytes(HEX)
|
hex = bytes(HEX)
|
||||||
oid = Oid(hex=hex)
|
oid = Oid(hex=hex)
|
||||||
self.assertEqual(oid.raw, RAW)
|
self.assertEqual(oid.raw, RAW)
|
||||||
self.assertEqual(oid.hex, HEX)
|
self.assertEqual(str(oid), HEX)
|
||||||
else:
|
else:
|
||||||
hex = bytes(HEX, "ascii")
|
hex = bytes(HEX, "ascii")
|
||||||
self.assertRaises(TypeError, Oid, hex=hex)
|
self.assertRaises(TypeError, Oid, hex=hex)
|
||||||
|
Reference in New Issue
Block a user