Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magic %paste not working in Python 3.3.2. TypeError: Type str doesn't support the buffer API #3386

Closed
admk opened this issue May 30, 2013 · 6 comments · Fixed by #4460
Closed
Labels
Milestone

Comments

@admk
Copy link

admk commented May 30, 2013

ipython3 version: 0.13.2
python3 version: 3.3.2
OS: Mac OS X 10.8.3

In [1]: %paste
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-86b9186405a3> in <module>()
----> 1 get_ipython().magic('paste')

/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
   2135         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2136         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2137         return self.run_line_magic(magic_name, magic_arg_s)
   2138
   2139     #-------------------------------------------------------------------------

/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2061                 args.append(sys._getframe(stack_depth).f_locals)
   2062             with self.builtin_trap:
-> 2063                 result = fn(*args)
   2064             return result
   2065

/usr/local/lib/python3.3/site-packages/IPython/frontend/terminal/interactiveshell.py in paste(self, parameter_s)

/usr/local/lib/python3.3/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    190     # but it's overkill for just that one bit of state.
    191     def magic_deco(arg):
--> 192         call = lambda f, *a, **k: f(*a, **k)
    193
    194         if isinstance(arg, collections.Callable):

/usr/local/lib/python3.3/site-packages/IPython/frontend/terminal/interactiveshell.py in paste(self, parameter_s)
    282         if 'q' not in opts:
    283             write = self.shell.write
--> 284             write(self.shell.pycolorize(block))
    285             if not block.endswith('\n'):
    286                 write('\n')

/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in <lambda>(src)
    575         # Python source parser/formatter for syntax highlighting
    576         pyformat = PyColorize.Parser().format
--> 577         self.pycolorize = lambda src: pyformat(src,'str',self.colors)
    578
    579     def init_pushd_popd_magic(self):

/usr/local/lib/python3.3/site-packages/IPython/utils/PyColorize.py in format(self, raw, out, scheme)
    127
    128     def format(self, raw, out = None, scheme = ''):
--> 129         return self.format2(raw, out, scheme)[0]
    130
    131     def format2(self, raw, out = None, scheme = ''):

/usr/local/lib/python3.3/site-packages/IPython/utils/PyColorize.py in format2(self, raw, out, scheme)
    174         lines_append = self.lines.append
    175         while 1:
--> 176             pos = raw_find('\n', pos) + 1
    177             if not pos: break
    178             lines_append(pos)

TypeError: Type str doesn't support the buffer API
@takluyver
Copy link
Member

It looks like this was fixed in the big pull request #1715, which wasn't backported to the 0.13 series. And I guess it's presumably OS X specific - we'd probably have noticed it on Windows.

In principle this is a candidate for backporting a fix, but I don't think we're planning another 0.13 release.

@minrk
Copy link
Member

minrk commented Jul 6, 2013

There (almost certainly) won't be another 0.13 release. Closing as fixed in 1.0.

@minrk minrk closed this as completed Jul 6, 2013
@takluyver takluyver reopened this Oct 30, 2013
@takluyver
Copy link
Member

Reopening as it turns out that it is an issue on Windows after all, if you have the pywin32 module installed.

@breamoreboy
Copy link

In [1]: %paste

TypeError Traceback (most recent call last)
in ()
----> 1 get_ipython().magic('paste')

c:\python33\lib\site-packages\IPython\core\interactiveshell.py in magic(self, arg_s)
2171 magic_name, _, magic_arg_s = arg_s.partition(' ')
2172 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2173 return self.run_line_magic(magic_name, magic_arg_s)
2174
2175 #-------------------------------------------------------------------------

c:\python33\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line)
2092 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2093 with self.builtin_trap:
-> 2094 result = fn(args,*kwargs)
2095 return result
2096

c:\python33\lib\site-packages\IPython\terminal\interactiveshell.py in paste(self, parameter_s)

c:\python33\lib\site-packages\IPython\core\magic.py in (f, _a, *_k)
190 # but it's overkill for just that one bit of state.
191 def magic_deco(arg):
--> 192 call = lambda f, _a, *_k: f(_a, *_k)
193
194 if isinstance(arg, collections.Callable):

c:\python33\lib\site-packages\IPython\terminal\interactiveshell.py in paste(self, parameter_s)
228 if 'q' not in opts:
229 write = self.shell.write
--> 230 write(self.shell.pycolorize(block))
231 if not block.endswith('\n'):
232 write('\n')

c:\python33\lib\site-packages\IPython\core\interactiveshell.py in (src)
595 # Python source parser/formatter for syntax highlighting
596 pyformat = PyColorize.Parser().format
--> 597 self.pycolorize = lambda src: pyformat(src,'str',self.colors)
598
599 def init_pushd_popd_magic(self):

c:\python33\lib\site-packages\IPython\utils\PyColorize.py in format(self, raw, out, scheme)
130
131 def format(self, raw, out = None, scheme = ''):
--> 132 return self.format2(raw, out, scheme)[0]
133
134 def format2(self, raw, out = None, scheme = ''):

c:\python33\lib\site-packages\IPython\utils\PyColorize.py in format2(self, raw, out, scheme)
177 lines_append = self.lines.append
178 while 1:
--> 179 pos = raw_find('\n', pos) + 1
180 if not pos: break
181 lines_append(pos)

TypeError: Type str doesn't support the buffer API

In [2]:

takluyver added a commit to takluyver/ipython that referenced this issue Oct 30, 2013
Ensure that we get unicode from the clipboard when using pywin32.
Closes ipythongh-3386

Also catches the empty clipboard case and displays a short error
message, instead of a huge traceback.
@takluyver
Copy link
Member

@breamoreboy : can you check that PR #4460 fixes it for you? Thanks.

@breamoreboy
Copy link

I've tried it with a simple one liner, a pile of import statements and then a function definition and all worked fine. Thank you everybody :)

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
Ensure that we get unicode from the clipboard when using pywin32.
Closes ipythongh-3386

Also catches the empty clipboard case and displays a short error
message, instead of a huge traceback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants