# Feature or enhancement

### Proposal:

Add the ability to force `shlex.quote` to always return an escaped / quoted string, avoiding the expensive regex-ing of a straggly set of characters (currently `r'[^\w@%+=:,./-]'`) .

Different shells have slightly different sets of special characters, eg sometimes including `#`, sometimes not. To quell one's pedantic paranoia of strings being incorrectly escaped due to an incomplete regex check, we extend the signature of shlex.quote in a perfectly backwards compatible way which skips the regex and goes straight to the escaping.

Changes `shlex.quote`'s signature from
```py
def quote(s):
```
to
```py
def quote(s, always=False):
```

`always` is of `bool` type, and by default is `False`, which produces the existing behaviour of the function.

### Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

### Links to previous discussion of this feature:

_No response_

<!-- gh-linked-prs -->
### Linked PRs
* gh-119674
<!-- /gh-linked-prs -->

shlex.quote: Add 'always' keyword argument
This is a GitHub Issue
repo:cpython
owner:python
Title : shlex.quote: Add 'always' keyword argument
Issue date:

--- start body ---
# Feature or enhancement

### Proposal:

Add the ability to force `shlex.quote` to always return an escaped / quoted string, avoiding the expensive regex-ing of a straggly set of characters (currently `r'[^\w@%+=:,./-]'`) .

Different shells have slightly different sets of special characters, eg sometimes including `#`, sometimes not. To quell one's pedantic paranoia of strings being incorrectly escaped due to an incomplete regex check, we extend the signature of shlex.quote in a perfectly backwards compatible way which skips the regex and goes straight to the escaping.

Changes `shlex.quote`'s signature from
```py
def quote(s):
```
to
```py
def quote(s, always=False):
```

`always` is of `bool` type, and by default is `False`, which produces the existing behaviour of the function.

### Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

### Links to previous discussion of this feature:

_No response_

<!-- gh-linked-prs -->
### Linked PRs
* gh-119674
<!-- /gh-linked-prs -->

--- end body ---
