GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Module imports itself — CodeQL query help 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-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
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.