Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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!


It'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...


It'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.


    if logger.isEnabledFor(logging.DEBUG):
        logger.debug(f'{expensive_func()}')


I 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!


That’s how you defer an expensive function. The fstring part is the joke.


Disable it in pylintrc. Pylint is unusable without a good config file anyway.


Ideally the defaults should be sensible. I have found they mostly are, except the f-string one.


For 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.


on 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.


pylint 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])))




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: