pylint和共享同名的类,显示没有会员错误

发布于 2025-02-07 17:43:53 字数 291 浏览 1 评论 0原文

我有一个包含多个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声情话 2025-02-14 17:43:53

我设法通过使用相对导入来使它起作用,
因此,从

.config import import

我还需要

config

添加一个空__ init __. py file:

 Lambda1 (folder)
 |_  __init__.py
 |_  config.py
 |_  lambda_function.py 
Lambda2 (folder)
 |_  __init__.py
 |_  config.py
 |_  lambda_function.py 

这将获取Pylint检测正确的类。

下一个问题是这些变化将导致Lambda不再起作用。

为了使lambda再次工作,我在每个Lambda文件夹中添加了一个文件夹:

 Lambda1 (folder)
 |_  app (folder)
    |_  __init__.py
    |_  config.py
    |_  lambda_function.py 
Lambda2 (folder)
 |_  app (folder)
    |_  __init__.py
    |_  config.py
    |_  lambda_function.py 

并从中更新了Lambda处理程序:对此

Handler: lambda_function.lambda_handler

Handler: app.lambda_function.lambda_handler

我不太高兴我需要重组文件并更新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:

 Lambda1 (folder)
 |_  __init__.py
 |_  config.py
 |_  lambda_function.py 
Lambda2 (folder)
 |_  __init__.py
 |_  config.py
 |_  lambda_function.py 

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:

 Lambda1 (folder)
 |_  app (folder)
    |_  __init__.py
    |_  config.py
    |_  lambda_function.py 
Lambda2 (folder)
 |_  app (folder)
    |_  __init__.py
    |_  config.py
    |_  lambda_function.py 

And updated the lambda handler from this:

Handler: lambda_function.lambda_handler

to this:

Handler: app.lambda_function.lambda_handler

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文