I have a python application that uses the python logging library for some time now for printing messages both on the screen and on time rotating files and works fine.
The logging configuration is as follows:
import logging
from logging.handlers import TimedRotatingFileHandler
logging.basicConfig(level=logging.INFO if debug is not True else logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
handlers=[
TimedRotatingFileHandler(log_filename, when='midnight', interval=1),
logging.StreamHandler()
]
)
My problem is that PyCharm keeps highlighting the logging.basicConfig part of the configuration with the following warning:
Unexpected argument(s)
Possible callees:
basicConfig(*, filename: Optional[str]=..., filemode: str=..., format: str=..., datefmt: Optional[str]=..., level: Union[int, str, None]=..., stream: IO[str]=...) basicConfig()
Inspection info: Reports discrepancies between declared parameters and actual arguments, as well as incorrect arguments (e.g. duplicate named arguments) and incorrect argument order. Decorators are analyzed, too.
And it goes out only if I remove the handlers=[...] part of the code.
Did the basicConfig's arguments change on a specific version? If yes, what is the proposed way to achieve the same thing?
I'm using python 3.6 and pycharm 2020.1 (but had the same warning for at least the past 3 updates)
This issue is reported on PyCharm bug tracker at https://youtrack.jetbrains.com/issue/PY-39762 . In short: the new keyword arguments of basicConfig in Python 3, like handler, are not recognized.
That issue also mentions a workaround:
Put a caret on
basicConfig- Right Click - Go to - Declaration or Usages - Click on a star on the left (on a gutter) -logging/__init__.pyishould be opened - Annotate allbasicConfigdefinitions with@overload.
I tested it and it worked. In my case PyCharm no longer complains about force=True argument.
Did the basicConfig's arguments change on a specific version?
You can always check the docs for that: https://docs.python.org/3/library/logging.html#logging.basicConfig :
Changed in version 3.2: The style argument was added.
Changed in version 3.3: The handlers argument was added. Additional checks were added to catch situations where incompatible arguments are specified (e.g. handlers together with stream or filename, or stream together with filename).
Changed in version 3.8: The force argument was added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With