CodeQL documentation

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-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

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy