Text of codeql.github.com › codeql-query-help › python › py-import-own-module as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

Module imports itself — CodeQL query help documentation

CodeQL query help documentation » CodeQL query help for Python » Module imports itself ¶ ID: py/import-own-module Kind: problem Security severity: Severity: recommendation Precision: very-high Tags: - quality - maintainability - useless-code Query suites: - python-code-quality.qls - 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 form mod.name where “mod” is the name of the current module to name . Example ¶ In this example the module, ModuleImportsItself imports itself and has an expression referencing the module it is in as well. import ModuleImportsItself def factorial ( n ): if n <= 0 : return 1 return n * ModuleImportsItself . factorial ( n - 1 ) The import can be removed and the reference can be corrected. def factorial ( n ): if n <= 0 : return 1 return n * factorial ( n - 1 ) References ¶ Python: Modules . © GitHub, Inc.

Terms Privacy