pylint和共享同名的类,显示没有会员错误
我有一个包含多个AWS lambdas的项目。每个lambda都有自己的配置类,根据lambda,将具有不同的成员。我遇到的问题是Pylint显示“类实例没有成员”(E1101)错误,因为它从其他lambda中选择了配置类。有没有办法迫使它在目录中选择类? 我正在使用VSCODE,项目的结构如下:
Lambda1 (folder)
|_ config.py
|_ lambda_function.py
Lambda2 (folder)
|_ config.py
|_ lambda_function.py
I've have a project that contains multiple AWS Lambdas. Each Lambda has their own Config class which will have different members depending on the Lambda. The issue I'm having is that Pylint is showing "Instance of class has no member" (E1101) error because its picking the Config class from a different Lambda. Is there a way to force it to select the class within its directory?
I'm using VSCode and the structure of my project is as follows:
Lambda1 (folder)
|_ config.py
|_ lambda_function.py
Lambda2 (folder)
|_ config.py
|_ lambda_function.py
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法通过使用相对导入来使它起作用,
因此,从
.config import import
我还需要
config
添加一个空
__ init __. py
file:这将获取Pylint检测正确的类。
下一个问题是这些变化将导致Lambda不再起作用。
为了使lambda再次工作,我在每个Lambda文件夹中添加了一个文件夹:
并从中更新了Lambda处理程序:对此
:
我不太高兴我需要重组文件并更新Lambda处理程序,因此将继续继续查看替代解决方案以避免这种情况。
I managed to get it working by using relative import,
so instead of
from config import Config
do
from .config import Config
I also need to add an empty
__init__.py
file:This would get Pylint to detect the correct class.
The next issue was that these changes would cause the lambda to no longer work.
To get the lambda working again I added a folder within each lambda folder like this:
And updated the lambda handler from this:
to this:
I'm not too happy that I need to restructure the files and update the lambda handler, so will continue looking at alternative solutions to avoid this.