Skip to content

SyntaxWarning: invalid escape sequence in _models.py when running Azure CLI on macOS #31789

@RevenantBob

Description

@RevenantBob

Describe the bug

When running the azure-cli on macOS (Homebrew install), Python shows SyntaxWarning messages about invalid escape sequences in docstrings within the azure.batch.models._models.py file.

Related command

az login

Errors

/opt/homebrew/Cellar/azure-cli/2.75.0/libexec/lib/python3.12/site-packages/azure/batch/models/_models.py:9067: SyntaxWarning: invalid escape sequence '\ '
  """The source port ranges to match for the rule. Valid values are '\ *' (for all ports 0 - 65535),
/opt/homebrew/Cellar/azure-cli/2.75.0/libexec/lib/python3.12/site-packages/azure/batch/models/_models.py:9235: SyntaxWarning: invalid escape sequence '\ '
  using brackets (for example abc[\ *] would match a file named abc*\ ). Note that both and / are

Issue script & Debug output

Not sure this step is necessary for a syntax error telling the line number.

/opt/homebrew/Cellar/azure-cli/2.75.0/libexec/lib/python3.12/site-packages/azure/batch/models/_models.py:9067: SyntaxWarning: invalid escape sequence '\ '
  """The source port ranges to match for the rule. Valid values are '\ *' (for all ports 0 - 65535),
/opt/homebrew/Cellar/azure-cli/2.75.0/libexec/lib/python3.12/site-packages/azure/batch/models/_models.py:9235: SyntaxWarning: invalid escape sequence '\ '
  using brackets (for example abc[\ *] would match a file named abc*\ ). Note that both and / are
Expected behavior
No SyntaxWarning should appear. Backslashes in docstrings should be escaped (\\) or the string should be marked as a raw string (r'...').

Expected behavior

No SyntaxWarning should appear. Backslashes in docstrings should be escaped (\) or the string should be marked as a raw string (r'...').

Environment Summary

macOS Sequoia 15.5 (24F74)
Python 3.12
Azure CLI installed via Homebrew (azure-cli/2.75.0)

Additional context

This is a docstring only — so there’s no runtime breakage. It just clutters the output with warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions