Title: single and double quotes stripped upon paste with MacPorts libedit
Type: behavior Stage:
Components: macOS Versions: Python 3.4
Status: open Resolution:
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 2018-03-13 21:01 by ned.deily.

Messages (11)
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:
Results in:

Same paste into 2.7.6 is as expected:
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
SyntaxError: invalid character in identifier
>>> [“Test”][‘Test’]
  File "<stdin>", line 1
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:
>>> print("{’Test’}")   
>>> print("{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. vs 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 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.
Date User Action Args
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