Skip to content

Remove Unnecessary Cast

Sourcery refactoring id: remove-unnecessary-cast

Description

Remove unnecessary casts to int, str, float and bool

Before

num_hats = 1
update_hat_count(int(num_hats))

After

num_hats = 1
update_hat_count(num_hats)

Explanation

If a variable is already an int, str, float or bool it is unnecessary to wrap it in the associated call later on in the code. Removing these unnecessary casts is a small improvement in readability, and can eliminate the mental overhead of trying to figure out why or whether the cast is required.

Back to top