GH-145247: Implement _PyTuple_FromPair#145325
GH-145247: Implement _PyTuple_FromPair#145325sergey-miryanov wants to merge 8 commits intopython:mainfrom
Conversation
eendebakpt
left a comment
There was a problem hiding this comment.
To minor comments on the test, but overall this looks good!
| def test_tuple_from_pair(self): | ||
| # Test _PyTuple_FromPair, _PyTuple_FromPairSteal | ||
| ctors = (("_PyTuple_FromPair", _testinternalcapi._tuple_from_pair), | ||
| ("_PyTuple_FromPairSteal", _testinternalcapi._tuple_from_pair_steal)) |
There was a problem hiding this comment.
The _testinternalcapi._tuple_from_pair_steal that wraps _PyTuple_FromPairSteal increments references to the arguments. For that reason there is no way to make a distinction between the _testinternalcapi._tuple_from_pair and _testinternalcapi._tuple_from_pair._tuple_from_pair_steal in the tests)
I would either change the name of _tuple_from_pair_steal or add a comment to make this clear.
There was a problem hiding this comment.
I'm not sure I understand what you mean. Could you elaborate please?
You are right that tests seem equals from point of view, but we need to test both functions to check a) their behavior and b) absence of the leak if we run it with -R option.
There was a problem hiding this comment.
The test is good indeed.
What I meant is that _testinternalcapi._tuple_from_pair_steal is not stealing references (since the arguments are incremented before passing to _PyTuple_FromPairSteal. So a (way too long) descriptive name would be _testinternalcapi._wraps_tuple_from_pair_steal_but_does_not_actually_steal.
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
|
|
||
| static PyMethodDef test_methods[] = { | ||
| {"_tuple_from_pair", _tuple_from_pair, METH_VARARGS}, | ||
| {"_tuple_from_pair_steal", _tuple_from_pair_steal, METH_VARARGS}, |
There was a problem hiding this comment.
I don't think that the _ underscore prefix is useful here. Other _testinternalcapi functions don't use an _ underscore prefix.
| def test_tuple_from_pair(self): | ||
| # Test _PyTuple_FromPair, _PyTuple_FromPairSteal | ||
| ctors = (("_PyTuple_FromPair", _testinternalcapi._tuple_from_pair), | ||
| ("_PyTuple_FromPairSteal", _testinternalcapi._tuple_from_pair_steal)) |
There was a problem hiding this comment.
I would prefer a more flat structure:
def check_tuple_from_pair(self, from_pair):
...
def test_tuple_from_pair(self):
# Test _PyTuple_FromPair()
from_pair = _testinternalcapi._tuple_from_pair
self.check_tuple_from_pair(from_pair)
def test_tuple_from_pair_steal(self):
# Test _PyTuple_FromPairSteal()
from_pair = _testinternalcapi._tuple_from_pair_steal
self.check_tuple_from_pair(from_pair)|
|
||
| self.assertRaises(TypeError, ctor, 1, 2, 3) | ||
| self.assertRaises(TypeError, ctor, 1) | ||
| self.assertRaises(TypeError, ctor) |
There was a problem hiding this comment.
nitpick: i suggest moving these checks at the end.
| self.assertFalse(gc.is_tracked(ctor(True, False))) | ||
| self.assertTrue(gc.is_tracked(ctor(temp, (1, 2)))) | ||
| self.assertTrue(gc.is_tracked(ctor(temp, 1))) | ||
| self.assertTrue(gc.is_tracked(ctor([], {}))) |
There was a problem hiding this comment.
You may reuse self._tracked() and self._not_tracked() methods for these checks.
Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
PyTuple_FromPair#145247