Title: shlex.pop_source() leaks punctuation buffered from the popped source · Issue #158785 · python/cpython · GitHub
Open Graph Title: shlex.pop_source() leaks punctuation buffered from the popped source · Issue #158785 · python/cpython
X Title: shlex.pop_source() leaks punctuation buffered from the popped source · Issue #158785 · python/cpython
Description: Bug report Bug description: Documented behaviour: Python standard-library documentation, shlex.pop_source(): "Pop the last-pushed input source from the input stack." Together with shlex.push_source(): "Push an input source stream onto th...
Open Graph Description: Bug report Bug description: Documented behaviour: Python standard-library documentation, shlex.pop_source(): "Pop the last-pushed input source from the input stack." Together with shlex.push_source...
X Description: Bug report Bug description: Documented behaviour: Python standard-library documentation, shlex.pop_source(): "Pop the last-pushed input source from the input stack." Together with shlex.p...
Opengraph URL: https://github.com/python/cpython/issues/158785
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"shlex.pop_source() leaks punctuation buffered from the popped source","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\n**Documented behaviour:** Python standard-library documentation, shlex.pop_source(): \"Pop the last-pushed input source from the input stack.\" Together with shlex.push_source(): \"Push an input source stream onto the input stack.\"\r\n\r\n**Expected:** ['a']\r\n\r\n**Actual:** [';', 'a']\r\n\r\n```python\r\nimport shlex\r\n\r\nP, C = 'a', 'b'\r\nif not all(s and s.isascii() and s.isalpha() for s in (P, C)):\r\n print('REFUTATION REJECTED: input must be nonempty ASCII letters')\r\nelse:\r\n expected = list(shlex.shlex(P + ' ', posix=True, punctuation_chars=';'))\r\n lexer = shlex.shlex(P + ' ', posix=True, punctuation_chars=';')\r\n lexer.push_source(C + ';tail')\r\n token = lexer.get_token()\r\n if token != C:\r\n print('REFUTATION REJECTED: pushed token was', repr(token))\r\n else:\r\n lexer.pop_source()\r\n actual = list(lexer)\r\n if actual != expected:\r\n print('REFUTATION CONFIRMED:', (P, C), 'actual:', actual, 'expected:', expected)\r\n else:\r\n print('REFUTATION REJECTED: restored source matches independent reference')\r\n```\r\n\r\nOutput on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library `shlex`:\r\n\r\n```\r\nREFUTATION CONFIRMED: ('a', 'b') actual: [';', 'a'] expected: ['a']\r\n```\r\n\r\nThis report was found and written by an automated property-testing tool I run ([bugforge](https://github.com/augusto-rehfeldt/bugforge)). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/shlex-20261003-015527-c4\r\n\r\n### CPython versions tested on:\r\n\r\n3.14\r\n\r\n### Operating systems tested on:\r\n\r\nWindows\r\n","author":{"url":"https://github.com/augusto-rehfeldt","@type":"Person","name":"augusto-rehfeldt"},"datePublished":"2026-10-04T01:08:25Z","url":"https://github.com/python/cpython/issues/158785"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:493df1ad-141a-ca5b-64d9-db9174423adc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C674:299992:1FE4862:29F306C:6B023681 |
| html-safe-nonce | ed20bd857b5a1afb752fab86690514085b72e8ebcca66b268f4f013f35c11d19 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjc0OjI5OTk5MjoxRkU0ODYyOjI5RjMwNkM6NkIwMjM2ODEiLCJ2aXNpdG9yX2lkIjoiNTA4MTcyMDM2MDU1OTMyNjg0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5ae649de4b8088aaa626fb087833a50f50795d88f76037566ea8d4c02a38baaa |
| hovercard-subject-tag | issue:5695117039 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/158785/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ab09c9ace705433657b3473659bbaee2397cf611036465b26e43f4b8f38fc5f7/python/cpython/issues/158785 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ab09c9ace705433657b3473659bbaee2397cf611036465b26e43f4b8f38fc5f7/python/cpython/issues/158785 |
| og:image:alt | Bug report Bug description: Documented behaviour: Python standard-library documentation, shlex.pop_source(): "Pop the last-pushed input source from the input stack." Together with shlex.push_source... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | augusto-rehfeldt |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width