Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Module imports itself

ID: py/import-own-moduleKind: problemSecurity severity: Severity: recommendationPrecision: very-highTags:   - quality   - maintainability   - useless-codeQuery suites:   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

There is no need for a module to import itself. A module importing itself may lead to errors as the module may be in an incomplete state when imported by itself.

Recommendation

Remove the import statement. Convert all expressions of the formmod.name where “mod” is the name of the current module toname.

Example

In this example the module,ModuleImportsItself imports itself and has an expression referencing the module it is in as well.

importModuleImportsItselfdeffactorial(n):ifn<=0:return1returnn*ModuleImportsItself.factorial(n-1)

The import can be removed and the reference can be corrected.

deffactorial(n):ifn<=0:return1returnn*factorial(n-1)

References


[8]ページ先頭

©2009-2025 Movatter.jp