Skip to content

Remove Unnecessary Cast

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery refactoring id: remove-unnecessary-cast

Section titled “Sourcery refactoring id: remove-unnecessary-cast”

Remove unnecessary casts to int, str, float and bool

num_hats = 1
update_hat_count(int(num_hats))
num_hats = 1
update_hat_count(num_hats)

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.