orenlab / pytmbot

Flexible Telegram bot designed to manage Docker containers, monitor server status, and extend its functionality through a plugin system
https://orenlab.github.io/pytmbot/
MIT License
7 stars 2 forks source link

Replace this "re.sub()" call by a "str.replace()" function call. #54

Closed orenlab closed 2 months ago

orenlab commented 2 months ago

Describe the bug str.replace should be preferred to re.sub in get_disk_usage in psutil_adapter module

An re.sub call always performs an evaluation of the first argument as a regular expression, even if no regular expression features were used. This has a significant performance cost and therefore should be used with care.

When re.sub is used, the first argument should be a real regular expression. If it’s not the case, str.replace does exactly the same thing as re.sub without the performance drawback of the regex.

This rule raises an issue for each re.sub used with a simple string as first argument which doesn’t contains special regex character or pattern.

orenlab commented 2 months ago

Fix in 07e4c6a