6 ms·
I love f-strings. I just wish tools like pylint would shut up when I pass f-strings to the logging module. I as the developer understand and accept the extra na
by sleavey 7y ago
I love f-strings. I just wish tools like pylint would shut up when I pass f-strings to the logging module. I as the developer understand and accept the extra nanosecond of processor time to parse the string that might not be logged anywhere!
- sametmax 7y agoDisable it in pylintrc. Pylint is unusable without a good config file anyway.
- sleavey 7y agoIdeally the defaults should be sensible. I have found they mostly are, except the f-string one.
- baq 7y agoon the contrary, i've seen code slow down by 50% due to a log.debug() that wasn't even emitted in prod. should've seen my face when i saw the pyspy flamechart.
- sametmax 7y agoFor something as finely tuned as pylint, my sensible default and your would never be the same. I don't want it to scream on a missing docstring for every single thing. I do want to be able to use a, b and x as variables. No, this root var is not a constant, don't ask me for uppercase. Etc.
- emidln 7y agopylint still sucks at partial function definitions. It wants to name anything that exists in the module scope that isn't an explicit function definition with CAPS_LOCK_MODE. $ pylint pylint_sucks_at_partials.py ************* Module pylint_sucks_at_partials pylint_sucks_at_partials.py:7:0: C0103: Constant name "add5" doesn't conform to UPPER_CASE naming style (invalid-name) The program in question: #!/usr/bin/env python """ proving pylint still sucks at partials """ from functools import partial from operator import add add5 = partial(add, 5) if __name__ == '__main__': import sys print(add5(int(sys.argv[1])))
- orf 7y agoIt's not always a nanosecond, some string representations can take a while to create. In poorly coded Django models they could involve a trip to the database.
- mixmastamyk 7y agoif logger.isEnabledFor(logging.DEBUG): logger.debug(f'{expensive_func()}')
- orf 7y agoI hope that’s a joke, because that is a verbose and ridiculous way of duplicating the work that the logging module does, while also making the code less readable and maintainable!
- mixmastamyk 7y agoThat’s how you defer an expensive function. The fstring part is the joke.
- MapleWalnut 7y agoIt's not just performance! Using percent formatting is superior in many ways: - errors that occur in formatting a message will be logged instead of raising an exception into your application - error reporting services like Sentry can properly aggregate events - interpolation won't occur if you don't have the logging level enabled - it's recommend by the Python docs: https://docs.python.org/3/howto/logging-cookbook.html#use-of-alternative-formatting-styles https://docs.python.org/3/howto/logging-cookbook.html#use-of...