You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you want to show that the same type is used in different places - use TypeVar instead of Any.
R7 Redundant "else"
on L41,42,43,44
There is a well-known pattern "if a: return one else: return two". In fact, the else keyword is redundant, because when first if condition evaluates to True, the function returns, otherwise control flow goes on. Removing else makes the code cleaner and easier to read.
TypeError, not IndexError
Moving type error handling to top is more readable
Suggested change:
ifnotisinstance(i, int):
raiseTypeError("Index must be int")
self._internal_list[i%len(self)] =value
L10 Modify in-place and return
on L66
There are functions that receive input and return output. There are functions that receive some object and modify it in-place. For example, reversed() vs list.reverse(), dataframe.apply() vs dataframe.apply(inplace=True). Doing both at the same time is confusing: when function returns something, it's not expected that it has any side effect, but here it does.
Maybe it was defined like that in a specification, but anyway it looks weird.
R1 Missing type hints
on L66,71,74,77
Type hints help humans and linters (like mypy) to understand what to expect "in" and "out" for a function. Not only it serves as a documentation for others (and you after some time, when the code is wiped from your "brain cache"), but also allows using automated tools to find type errors.
Missing return type hint
The text was updated successfully, but these errors were encountered:
Summary
Review link
R13 TypeVar not used
on L9,15,40
When you want to show that the same type is used in different places - use TypeVar instead of Any.
R7 Redundant "else"
on L41,42,43,44
There is a well-known pattern "if a: return one else: return two". In fact, the else keyword is redundant, because when first if condition evaluates to True, the function returns, otherwise control flow goes on. Removing else makes the code cleaner and easier to read.
Suggested change:
L10 Modify in-place and return
on L66
There are functions that receive input and return output. There are functions that receive some object and modify it in-place. For example, reversed() vs list.reverse(), dataframe.apply() vs dataframe.apply(inplace=True). Doing both at the same time is confusing: when function returns something, it's not expected that it has any side effect, but here it does.
Maybe it was defined like that in a specification, but anyway it looks weird.
R1 Missing type hints
on L66,71,74,77
Type hints help humans and linters (like mypy) to understand what to expect "in" and "out" for a function. Not only it serves as a documentation for others (and you after some time, when the code is wiped from your "brain cache"), but also allows using automated tools to find type errors.
Missing return type hint
The text was updated successfully, but these errors were encountered: