gaogaotiantian / objprint

A library that can print Python objects in human readable format
Apache License 2.0
519 stars 43 forks source link

Question: Is it possible to make linters happy when using `install()` #101

Closed RmZeta2718 closed 11 months ago

RmZeta2718 commented 11 months ago

install() basically injects op into builtins, but linters like mypy or pyright is not aware of that, so IDEs (vscode with pylance, for example) complains about that: "op" is is not defined Pylance(reportUndefinedVariable)

Besides manually ignoring type checking where op is used (# type: ignore), is it even possible to make mypy or pyright happy? Or should I raise an issue there?

gaogaotiantian commented 11 months ago

Unfortunately, linters won't be happy with injecting a random function into builtins. Normally you can't do much magic if you want to make linters happy. So, you can explicitly from objprint import op, or, if your code does not rely on print, you can do a dark magic - op.install("print"), which will replace the print function in builtins. linters will be happy as they know that's a built-in function, and all your prints become an objprint print.

RmZeta2718 commented 11 months ago

Thanks for your super fast reply! Sad to know that I can't inject op into linters, but I love the dark magic.