FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

A option that choose between single quote and double quote in shlex.quote · Issue #90630 · python/cpython · GitHub

Repository navigation

A option that choose between single quote and double quote in shlex.quote #90630

Open

Description

BPO 46472
Nosy @ericvsmith, @I-love-study

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2022-01-22.14:35:44.407>
labels = ['type-feature', 'library']
title = 'A option that choose between single quote and double quote in shlex.quote'
updated_at = <Date 2022-01-22.17:34:50.674>
user = 'https://github.com/I-love-study'

bugs.python.org fields:

activity = <Date 2022-01-22.17:34:50.674>
actor = 'eric.smith'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2022-01-22.14:35:44.407>
creator = 'I-love-study'
dependencies = []
files = []
hgrepos = []
issue_num = 46472
keywords = []
message_count = 1.0
messages = ['411258']
nosy_count = 2.0
nosy_names = ['eric.smith', 'I-love-study']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46472'
versions = []

Activity

  1. I-love-study commented on Jan 22, 2022

    I-love-studymannequin
    MannequinAuthor

    shlex.quote always use single quote
    but in some shell (like Cmd on Windows), single quote cannot be recognized as a shell-escaped string, only double quote can.
    So I think a option that can choose between single quote and double quote is better

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-featureA feature request or enhancement
    on Jan 22, 2022
  3. transferred this issue fromon Apr 10, 2022
  4. calestyo commented on Jul 12, 2023

    Contributor

    It would be nice if this could further be extended to allow choosing to quote for dollar-single-quote quotes.

    These, like $'\t', are already supported by numerous shells (e.g. bash) but admittedly not all (e.g. any ash based shels like dash, busybox sh or klibc-utils sh).

    The next POSIX revision will standardise those quotes so in principle supporting them becomes mandatory for any shell that wants to be compatible.

    I think the main benefit of allowing to choose them would be that things like control chars, other arbitrary bytes that are not representable as valid UTF-8 and also tab and newline can be escaped more easily.

    Right now:

    >>> shlex.quote("a\nb")
    "'a\nb'"
    

    which is of course valid, but cannot be used e.g. if one wants to output a filename in an error message and all error messages should be exactly one line.

    The above would give e.g.

    >>> printf(f"Error: Cannot find the file {shlex.quote(f)}.", file=sys.stderr)
    Error: Cannot find the file a
    b.
    

    If shlex.quote would offer e.g. a flag that allows to use dollar-single- quote quotes it could instead escape the above example string to:

    "$'a\\nb'"
    

    Of course, the function would then need to know which characters it encodes how (in a sensible way).

  5. added a commit that references this issue on Jun 4, 2026
  6. added a commit that references this issue on Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL