Implement range.count#381
Conversation
| ); | ||
|
|
||
| if let PyObjectPayload::Range { ref range } = zelf.borrow().payload { | ||
| match needle.borrow().payload { |
There was a problem hiding this comment.
Instead of using the PyObjectPayload here, use the vm.isinstance type check to determine int type, and objint::get_value to retrieve the BigInt value.
There was a problem hiding this comment.
This works for the argument, but won't I still eventually need to use PyObjectPayload to pull out the actual RangeType? Apologies if I misunderstood you, I'm not entirely familiar with this project.
There was a problem hiding this comment.
No worries, thank you for your help! The idea is to use PyObjectPayload as little as possible. The objrange.rs file should contain a method get_value which will retrieve the payload for you. This saves a lot of duplicate code for borrow and matching on the payload type. Take a look at the objint::getvalue method for example. It returns you the BigInt contents of the integer. The same should be there for the range type.
Hope this helps!
There was a problem hiding this comment.
Btw, the problem with checking strictly on the payload is that this will eventually fail with subclasses. The isinstance check is more thorough and works for subclasses as well!
- Refactor range_count to use get_value and isinstance for pulling out the range and argument respectively
- Use get_value in all appropriate spots
2139a33 to
0cb661f
Compare
|
@windelbouwman I didn't find the Also, I modified a bunch of the other methods in the file to make use of |
|
This is exactly what I meant. Great job! |
Implements
countfor #293.