Message208821
Attached is a complete conversion of Modules/_randommodule.c. Three _random.Random methods were converted: seed, getrandbits and __new__.
There's was an problem converting _random.Random.__new__. I overcame it cleanly and think this patch is good. Details about the problem follow.
issue1486663 made various __new__ methods of built-in classes only do a '_PyArg_NoKeywords' check if the type is the class itself, i.e. not for sub-classes. This is to allow sub-classes to accept keyword arguments.
This means that for classes that do this, like _random.Random, converting using AC makes it so subclasses can't accept keyword arguments (unless the subclasses implement __new__ properly).
Still, it is possible to convert _random.Random.__new__ and also override __new__ in random.Random (random != _random, and random.Random subclasses _random.Random). This way subclasses of the latter can accept keyword arguments. Since anyone sub-classing _random.Random instead of random.Random can be expected to know to override __new__ or switch to random.Random, I think this is a good solution for this case.
The attached patch does as I suggest above and passes all tests in test_random, including 'test_random_subclass_with_kwargs' which checks this issue. Just to be sure, I also ran the entire test suite, and all tests pass. |
|
Date |
User |
Action |
Args |
2014-01-22 16:29:40 | taleinat | set | recipients:
+ taleinat, larry |
2014-01-22 16:29:40 | taleinat | set | messageid: <1390408180.72.0.200923723244.issue20180@psf.upfronthosting.co.za> |
2014-01-22 16:29:40 | taleinat | link | issue20180 messages |
2014-01-22 16:29:40 | taleinat | create | |
|