Avoid Pylint warning E1101: 'Instance of .. has no .. member' for class with dynamic attributes

后端 未结 6 1661
走了就别回头了
走了就别回头了 2020-11-27 04:02

Imagine a function which dynamically adds attributes to an object using setattr. The reason for doing so is that I want to map some external structure

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 04:55

    This page describes the error and gives an easy way to address it directly in the code. tl;dr

    Used when an object (variable, function, …) is accessed for a non-existent member.

    False positives: This message may report object members that are created dynamically, but exist at the time they are accessed.

    A commentor mentions that it can be disabled on a single line at the top of the file with # pylint: disable=no-member. I also found that you can use # pylint: disable=E1101 based on this reddit entry.

提交回复
热议问题