Python pylint如何在argparse中不引发任何成员消息?

Python pylint如何在argparse中不引发任何成员消息?,python,argparse,pylint,Python,Argparse,Pylint,我写了这样的代码 from argparse import Namespace class Config(Namespace): def __init__(self, filename): config = yaml.load(open(filename, 'r')) super(Config, self).__init__(**config) config = Config('some/path/where/yaml/file/exist')

我写了这样的代码

from argparse import Namespace

class Config(Namespace): 
    def __init__(self, filename):
        config = yaml.load(open(filename, 'r'))

        super(Config, self).__init__(**config)

config = Config('some/path/where/yaml/file/exist')

print(config.some_attr)
然后,塔架不会发出这样的警告

from argparse import Namespace

class Config(Namespace): 
    def __init__(self, filename):
        config = yaml.load(open(filename, 'r'))

        super(Config, self).__init__(**config)

config = Config('some/path/where/yaml/file/exist')

print(config.some_attr)
“Config”的实例没有“some attr”成员pylint(无成员)

但argparse方法的某些部分不会引发任何成员警告

parser = argparse.ArgumentParser("test")
parser.add_argument('--config', type=str, default='config')
args, _ = parser.parse_known_args()

args.test # no warning
args.config # no warning
此代码不会在pylint中引发任何警告

我很好奇,所以我查看了github中相应的代码。但是ArgumentParser.parse_knwon_args的第一个返回值也是Namespace对象


如何修复自定义配置类未引发警告消息?我不想在我的代码块中插入“#pylint:disable=no member”。模块(类)中是否有解决方案?

您可以定义一个
\uuuu getattribute\uuuu
函数,该函数将“安全地”从类中获取属性,pylint将不再抱怨

类MyAttributeClass:
def uu getattribute_uu(self,name):
对象。获取属性(self,name)

请注意,这意味着pylint将不会检测到对永远不存在的成员的引用,因此bug可能以这种方式潜入代码中。仅对需要具有动态属性的类使用此选项。

您可以定义一个
\uuu getattribute\uuuu
函数,该函数将“安全”地从类中获取属性,pylint将不再抱怨

类MyAttributeClass:
def uu getattribute_uu(self,name):
对象。获取属性(self,name)
请注意,这意味着pylint将不会检测到对永远不存在的成员的引用,因此bug可能以这种方式潜入代码中。仅对预期具有动态属性的类使用此选项