Skip to content

[CLEANUP][SONAR][LOW]: Identical if/elif branches in path_template normalization in schemas.py #2376

@crivetimihai

Description

@crivetimihai

Severity: LOW
File: mcpgateway/schemas.py
Lines: 1148-1151
Rule: python:S3923

Description

The if/elif branches perform identical operations when normalizing path_template:

Code

# Lines 1148-1151
if path_template and not path_template.startswith("/"):
    path_template = "/" + path_template.lstrip("/")
elif path_template:
    path_template = "/" + path_template.lstrip("/")  # Same as above!

Technical Analysis

  • if branch: path_template exists AND doesn't start with "/"
  • elif branch: path_template exists (but already starts with "/")

Both branches do "/" + path_template.lstrip("/"), but the elif branch is redundant - if the path already starts with "/", lstrip("/") removes the leading slash and then "/" is prepended, resulting in the same value.

Impact

None - code functions correctly due to idempotent operation. This is a clarity/maintainability issue.

Suggested Fix

Simplify to a single branch:

if path_template:
    # Normalize to ensure single leading slash
    path_template = "/" + path_template.lstrip("/")

Metadata

Metadata

Assignees

No one assigned

    Labels

    COULDP3: Nice-to-have features with minimal impact if left out; included if time permitschoreLinting, formatting, dependency hygiene, or project maintenance chorespythonPython / backend development (FastAPI)sonarSonarQube code quality findings

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions