return statement causes the control flow to be disrupted, making the else / elif block here unnecessary. This doesn't mean you can not use it, but it is recommended to refactor this for better readability.
Remove unnecessary calls of list/dict, can use []/{} which are faster and more readable.
raise AssertionError is preferred over bare assert statements. Whenever the use of assert is detected, the enclosed code will be removed when compiling to optimized byte code.
The assert statement is generally for unit-testing or finding issues during the development process. This does not mean you will necessarily see the error. On the other hand, raising an AssertionError means that the error will be raised by the code and that any calling processes can deal with this error as needed.
Brief description of what is fixed or changed
Remove unnecessary
else
/elif
used afterreturn
return
statement causes the control flow to be disrupted, making theelse
/elif
block here unnecessary. This doesn't mean you can not use it, but it is recommended to refactor this for better readability.Remove unnecessary calls of
list
/dict
, can use[]
/{}
which are faster and more readable.raise AssertionError
is preferred over bareassert
statements. Whenever the use of assert is detected, the enclosed code will be removed when compiling to optimized byte code. The assert statement is generally for unit-testing or finding issues during the development process. This does not mean you will necessarily see the error. On the other hand, raising an AssertionError means that the error will be raised by the code and that any calling processes can deal with this error as needed.