0

I'm trying to write a custom pylint checker to check usage of structlog calls. But I found, that astroid can't infer structlog calls. For example:

import astroid

snippet = """
import structlog
logger = structlog.getLogger()
logger.error("foo")
"""
node_a = astroid.extract_node(snippet)

print(node_a)
print(list(node_a.infer()))
print(list(node_a.func.infer()))

produces

Call(func=<Attribute.error l.4 at 0x10aa13650>,
     args=[<Const.str l.4 at 0x10aa13710>],
     keywords=[])
[Uninferable]
[Uninferable]

And if I do the same with logging:

import astroid

snippet = """
import logging
logger = logging.getLogger()
logger.error("foo")
"""
node_a = astroid.extract_node(snippet)

print(node_a)
print(list(node_a.infer()))
print(list(node_a.func.infer()))

it successfully infers:

Call(func=<Attribute.error l.4 at 0x10a82d750>,
     args=[<Const.str l.4 at 0x10a80c750>],
     keywords=[])
[Uninferable, <Const.NoneType l.None at 0x10b14cdd0>]
[Uninferable, <BoundMethod error of logging.Logger at 0x4478033808]

Any clues, why does it happen or how can I fix it?

eyeinthebrick
  • 528
  • 1
  • 5
  • 21

0 Answers0