I'm creating a custom Python CLI module using docx2pdf.
The docx2pdf module is using tqdm to display progress bars while the .docx files are being converted to .pdf.
In my module I'm using the CLI log parameter to enable/disable console logging output.
Switching progress bar output with tqdm is explained in Stack Overflow and GitHub posts:
- Silence tqdm's output while running tests or running the code via cron
- Can't hide console with PyInstaller #83
According to this information I'm adding the switch tqdm function:
from functools import partialmethod
from tqdm import tqdm
def tqdm_log(log: bool = False) -> None:
''' tqdm logging switch '''
if not log:
tqdm.__init__ = partialmethod(tqdm.__init__, disable=True)
It works correctly, but the LSP pyright module returns an error when using functools.partialmethod with tqdm.__init__:
Cannot assign member "__init__" for type "type [tqdm [_T@tqdm]]"...
Is there any way to make this code more elegant and/or resolve the LSP pyright error?
