rope icon indicating copy to clipboard operation
rope copied to clipboard

Refactor to avoid mixing bytes/str types

Open sergeyglazyrindev opened this issue 7 years ago • 2 comments

Hey guys! I've found one issue while development of my project:

In [1]: s = b'# -*- coding: utf-8 -*-\nfrom __future__ import unicode_literals\n'

In [2]: start = 12

In [3]: s[start] not in '=:'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-f25611814cc6> in <module>()
----> 1 s[start] not in '=:'

TypeError: 'in <string>' requires string as left operand, not int

Seems like this issue already fixed here: https://github.com/python-rope/rope/blob/master/rope/base/fscommands.py#L266

Actually, my fix was a little bit different but then I found one real problem in rope: we do mix in code checkings for bytes or str, that's bad, I'd like propose you to add StringSource, BytesSource python classes, and refactor all these checkings. I suspect we won't have big issues after such refactor cause most of the code covered by tests. Anyway how it's written now -> not so good, so I propose to refactor these checkings for bytes/string, analyze what's better for us (I suspect bytes) and then tie all code to one style because right now it's magic issues.....

sergeyglazyrindev avatar Jul 17 '17 18:07 sergeyglazyrindev

Sounds like a good idea, yes. I have no idea how widespread a problem this is in the codebase, would be interesting to find out.

soupytwist avatar Jul 24 '17 18:07 soupytwist

I'll schedule this investigation

sergeyglazyrindev avatar Jul 25 '17 11:07 sergeyglazyrindev