How to specify a default logger in non-node classes with Python types in VSCode?
Hi,
I'm using support classes that are not part of a node to represent things such as scene objects.
Here is one representing a cylinder:
# has to be imported like this
from rclpy import logging
class cylinder:
def __init__(
self,
center: Pose = None,
radius: float = None,
thickness: float = None,
logger: LoggerInterface = logging.get_logger('cylinder'),
):
self.center: Pose = center
self.radius: float = radius
self.thickness: float = thickness
self.logger: LoggerInterface = logger
As you can see, I defined a default logger. For this, since I'm not in a node, I'm directly calling it from the logging module of rclpy. I also defined a LoggerInterface class that is purely an un-implemented interface for typing.
This code works.
What is not working is VS Code functionalities. VS Code can't find logging.get_logger. So that it appears in white and no documentation is available, nor autocomplete.
Also, I can't find a class that VSCode can refer to, to strongly type self.logger. So that I had to rely on this custom interface to have some vs code features.
I know it is a detail, but since I plan to use these default loggers a lot, I would like to know if you have some clean solution to propose?
Thanks
Asked by thibd on 2022-07-19 14:35:22 UTC
Comments