Always define a module once. Do not import the module multiple times and/or import the module using different methods. It makes the code harder to understand. Import a module once and for all with only one import mechanism.
Non-Compliant Code Examples
importloggingimportlogging# do not import the same module again.
Compliant Code Examples
importtypingfromtypingimportcast
importlogging
importloggingfromloggingimportfoo# not an issue since we are using a from import
Seamless integrations. Try Datadog Code Analysis
Datadog Code Analysis
Try this rule and analyze your code with Datadog Code Analysis
How to use this rule
1
2
rulesets:- python-best-practices # Rules to enforce Python best practices.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Analysis scans to your CI pipelines