slm_lab/spec/spec_util.py
Function tick
has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring. Open
Open
def tick(spec, unit):
'''
Method to tick lab unit (experiment, trial, session) in meta spec to advance their indices
Reset lower lab indices to -1 so that they tick to 0
spec_util.tick(spec, 'session')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
TODO found Open
Open
# TODO expand to be more comprehensive
- Exclude checks
Comparison to false should be 'if cond is false:' or 'if not cond:' Open
Open
assert ps.get(spec, 'agent.0.net.gpu') == False, f'Distributed mode "synced" works with CPU only. Set gpu: false.'
- Read upRead up
- Exclude checks
Comparison to singletons should use "is" or "is not".
Comparisons to singletons like None should always be done
with "is" or "is not", never the equality operators.
Okay: if arg is not None:
E711: if arg != None:
E711: if None == arg:
E712: if arg == True:
E712: if False == arg:
Also, beware of writing if x when you really mean if x is not None
-- e.g. when testing whether a variable or argument that defaults to
None was set to some other value. The other value might have a type
(such as a container) that could be false in a boolean context!