Conversation
Remove mode which has been deprecated singe 2.0
a71048b to
9aa33dd
Compare
| def setup_bitgenerator(self, seed, mode=None): | ||
| kwargs = {} if mode is None else {"mode": mode} | ||
| return self.bit_generator(*seed, **kwargs) | ||
| def setup_bitgenerator(self, seed): |
Check notice
Code scanning / CodeQL
Mismatch between signature and use of an overridden method Note test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 6 months ago
To fix this issue, the method signature of the base class (or parent test class) setup_bitgenerator must be updated to be compatible with its usage and the subclass override. The best change is to modify the base class signature (at line 222) from accepting only seed to also accept an optional inc argument defaulting to None: def setup_bitgenerator(self, seed, inc: int | None = None):. This matches the overriding subclass method and fixes the call sites where inc is passed. For backward compatibility, in the body of the base method, if inc is not used, it simply passes it (as default) to the bit generator constructor, so there should be no unintended side effects.
| @@ -219,8 +219,8 @@ | ||
| data = [int(line.split(",")[-1].strip(), 0) for line in csv] | ||
| return {"seed": seed, "data": np.array(data, dtype=cls.dtype)} | ||
|
|
||
| def setup_bitgenerator(self, seed): | ||
| return self.bit_generator(*seed) | ||
| def setup_bitgenerator(self, seed, inc: int | None = None): | ||
| return self.bit_generator(*seed) if inc is None else self.bit_generator(*seed, inc=inc) | ||
|
|
||
| def test_default(self): | ||
| bg = self.setup_bitgenerator([None]) |
| cls.large_advance_final = 326675794918500479020985263602132957772 | ||
|
|
||
| def setup_bitgenerator(self, seed, mode=None, inc=0): | ||
| def setup_bitgenerator(self, seed, inc=0): |
Check notice
Code scanning / CodeQL
Mismatch between signature and use of an overridden method Note test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 6 months ago
The ideal solution is to update the parent class's method definition for setup_bitgenerator (at line 1915 in TestPCG64DXSM) so that its signature matches that of the overridden method in TestSquares. This involves adding counter=None and key=None arguments (with default values for backwards compatibility), and adjusting the implementation so that these are properly forwarded to self.bit_generator. We avoid changing existing functionality by retaining inc=0 (since the parent class expects it). Any calls to self.setup_bitgenerator in the parent class or subclasses will then consistently accept seed, inc, counter, and key as keyword arguments, preventing TypeErrors and maintaining Liskov substitutability.
To implement:
- Change the definition at line 1915 in
TestPCG64DXSMto:
def setup_bitgenerator(self, seed, inc=0, counter=None, key=None): - Pass
counterandkeyas keyword arguments toself.bit_generatorin the return statement, only if they are not None so that existing usages are not broken.
No further changes are needed to the child class or calls. All changes are in randomgen/tests/test_direct.py.
| @@ -1912,8 +1912,13 @@ | ||
| cls.large_advance_initial = 262626489767919729675955844831248137855 | ||
| cls.large_advance_final = 326675794918500479020985263602132957772 | ||
|
|
||
| def setup_bitgenerator(self, seed, inc=0): | ||
| return self.bit_generator(*seed, inc=inc) | ||
| def setup_bitgenerator(self, seed, inc=0, counter=None, key=None): | ||
| kwargs = {} | ||
| if counter is not None: | ||
| kwargs['counter'] = counter | ||
| if key is not None: | ||
| kwargs['key'] = key | ||
| return self.bit_generator(*seed, inc=inc, **kwargs) | ||
|
|
||
| def test_large_advance(self): | ||
| bg = self.setup_bitgenerator([0], inc=1) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #420 +/- ##
==========================================
- Coverage 95.50% 95.41% -0.09%
==========================================
Files 57 56 -1
Lines 8835 8750 -85
Branches 177 175 -2
==========================================
- Hits 8438 8349 -89
- Misses 382 387 +5
+ Partials 15 14 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Remove mode which has been deprecated singe 2.0