This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: single and double quotes stripped upon paste with MacPorts libedit
Type: behavior Stage: resolved
Components: macOS Versions: Python 3.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: ned.deily Nosy List: Jeff Doak, cheryl.sabella, demian.brecht, ned.deily, r.david.murray, ronaldoussoren
Priority: normal Keywords:

Created on 2015-03-06 22:37 by Jeff Doak, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (12)
msg237389 - (view) Author: Jeff Doak (Jeff Doak) Date: 2015-03-06 22:37
On MacBook. Copy/paste the following line into 3.4.2 interpreter session:
[“Test”][‘Test’]
Results in:
[Test][Test]

Same paste into 2.7.6 is as expected:
[“Test”][‘Test’]
msg237393 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-03-06 22:49
Those aren't actually quote marks, at least as you've cut and pasted them.  They are "smart quotes", which are not something Python recognizes outside of properly quoted strings.

That doesn't explain why they disappear, though, you should just get a syntax error.  Works fine on linux, by the way.
msg237397 - (view) Author: Demian Brecht (demian.brecht) * (Python triager) Date: 2015-03-06 23:19
I'm on OSX 10.10.2. Simply copy/pasting the line into both terminal and iterm yields

>>> [“Test”][‘Test’]
  File "<stdin>", line 1
    [“Test”][‘Test’]
          ^
SyntaxError: invalid character in identifier
>>> [“Test”][‘Test’]
  File "<stdin>", line 1
    [“Test”][‘Test’]
              ^
SyntaxError: invalid character in identifier

Are the smart quotes disappearing when the clipboard buffer is being copied into the terminal shell or when you hit enter? If it's on copy, what happens when you hit enter?
msg237401 - (view) Author: Jeff Doak (Jeff Doak) Date: 2015-03-06 23:39
I noticed they are smart quotes and came back to see David already mentioned it.
As for Demian's question:
2.7.6:
>>> print("{’Test’}")   
{’Test’}
3.4.2:
>>> print("{Test}") 
{Test}

It is upon paste that the quotes are lost. I'm on OSX 10.10.2 as well.
msg237403 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-03-06 23:47
You've already answered this but since I've already typed it: one possible pitfall here is the automatic smart quotes feature of the OS X text system which may or may not be a factor depending on which programs are in use.  You can disable smart quotes in: System Preferences -> Keyboard -> Text -> Use smart quotes and dashes (this is on OS X 10.10).

But we really need more details to try to explain what you are seeing.  Can you give a step by step procedure on how to reproduce, including exactly what apps are being used (e.g. Terminal.app vs iTerm.app vs IDLE), and the results of the following commands in a terminal shell:

python3.4 -c 'import sys;print(sys.version)'
python3.4 -c 'import readline;print(readline.__doc__)'
env | egrep '(LC)|(LANG)'
msg237404 - (view) Author: Jeff Doak (Jeff Doak) Date: 2015-03-07 00:16
I am in a standard Terminal session. I have a symbolic link for python 3.4:
/usr/bin/python -> /opt/local/bin/python3.4
so I can run python... or the following:
$ /opt/local/bin/python3.4 -c 'import sys;print(sys.version)'
3.4.2 (default, Oct 22 2014, 01:08:11) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)]

$ /opt/local/bin/python3.4 -c 'import readline;print(readline.__doc__)'
Importing this module enables command line editing using libedit readline.
msg237405 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-03-07 00:39
OK, thanks, now we're getting somewhere!  From the pathname (/opt/local/bin), I assume you are using the Python 3.4 from MacPorts and from the readline docstring that Python 3.4 is linked with BSD libedit rather than GNU readline.  MacPorts supplies its own, newer version of libedit rather than the Apple-supplied one shipped with OS X.  It looks there is something funky going on there such that the pasted characters are being edited. The python.org Python 3.4 links with the older system libedit and it does not display this behavior.  It could also be due to a patch in the MacPorts Python 3.4 or libedit.  In any case, there seems to be an easy workaround: have the MacPorts Python use GNU readline instead.  You can do that by running:

sudo port py34-readline

I'll leave this open to investigate further later, assuming the workaround works for you.
msg237406 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-03-07 00:40
Er, make that:

sudo port install py34-readline
msg237410 - (view) Author: Jeff Doak (Jeff Doak) Date: 2015-03-07 02:52
Thanks Ned and everyone!  It turns out that Ned was correct and it works fine now that I followed his instructions.
msg313762 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-03-13 16:01
Hi Ned,

Do you think this issue still needs follow up?
msg313777 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-03-13 21:01
Cheryl, as far as I know this is still an unresolved issue for at least some versions of Python and some versions of libedit.  I'd like to keep it open as a reminder.  If someone else wants to dig into it before I get around to it, feel free to do so.
msg407191 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-11-28 06:49
Getting back to this old issue, retesting with a current MacPorts Python 3.9.9 and libedit @20210910-3.1_1, I no longer see the problematic disappearance of the smart quotes; the example now produces the expected "invalid character in identifier" SyntaxError. So no further action is needed.
History
Date User Action Args
2022-04-11 14:58:13adminsetgithub: 67787
2021-11-28 06:49:06ned.deilysetstatus: open -> closed
resolution: out of date
messages: + msg407191

stage: resolved
2018-03-13 21:01:43ned.deilysetmessages: + msg313777
2018-03-13 16:01:26cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg313762
2015-03-07 02:59:07ned.deilysetassignee: ned.deily
title: single and double quotes stripped upon paste into interpreter -> single and double quotes stripped upon paste with MacPorts libedit
2015-03-07 02:52:31Jeff Doaksetmessages: + msg237410
2015-03-07 00:40:27ned.deilysetmessages: + msg237406
2015-03-07 00:39:41ned.deilysetmessages: + msg237405
2015-03-07 00:16:28Jeff Doaksetmessages: + msg237404
2015-03-06 23:47:32ned.deilysetmessages: + msg237403
2015-03-06 23:39:37Jeff Doaksetmessages: + msg237401
2015-03-06 23:19:56demian.brechtsetnosy: + demian.brecht
messages: + msg237397
2015-03-06 22:49:48r.david.murraysetnosy: + r.david.murray
messages: + msg237393
2015-03-06 22:37:16Jeff Doakcreate