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

PR: Fix error edge line in python2.7 #4155

Merged
merged 4 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions spyder/tests/tests_py3compat_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

import os
import re

root_path = os.path.realpath(os.path.join(os.getcwd(), 'spyder'))

pattern = re.compile("isinstance\(.*,.*str\)")


def test_dont_use_isinstance_str():
found = False
for dir_name, _, file_list in os.walk(root_path):
for fname in file_list:
if fname.endswith('.py') and fname != 'py3compat.py':
file = os.path.join(dir_name, fname)

for i, line in enumerate(open(file)):
for match in re.finditer(pattern, line):
print("{}\nline:{}, {}".format(file, i + 1, line))
found = True

assert found == False, ("Don't use builtin isinstance() function,"
"use spyder.py3compat.is_text_string() instead")
3 changes: 2 additions & 1 deletion spyder/widgets/panels/edgeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from qtpy.QtCore import Qt, QRect
from qtpy.QtGui import QPainter, QColor

from spyder.py3compat import is_text_string

class EdgeLine(QWidget):
"""Source code editor's edge line (default: 79 columns, PEP8)"""
Expand Down Expand Up @@ -53,7 +54,7 @@ def set_columns(self, columns):
"""Set edge line columns values."""
if isinstance(columns, tuple):
self.columns = columns
elif isinstance(columns, str):
elif is_text_string(columns):
self.columns = tuple(int(e) for e in columns.split(','))

self.update()
Expand Down
4 changes: 2 additions & 2 deletions spyder/widgets/panels/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from spyder.api.manager import Manager
from spyder.api.panel import Panel
from spyder.config.base import debug_print

from spyder.py3compat import is_text_string

class PanelsManager(Manager):
"""
Expand Down Expand Up @@ -94,7 +94,7 @@ def get(self, name_or_klass):
:param name_or_klass: Name or class of the panel to retrieve.
:return: The specified panel instance.
"""
if not isinstance(name_or_klass, str):
if not is_text_string(name_or_klass, str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rlaverde, this call is wrong because is_text_string only receives one argument.

name_or_klass = name_or_klass.__name__
for zone in range(4):
try:
Expand Down
4 changes: 2 additions & 2 deletions spyder/workers/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Local imports
from spyder import __version__
from spyder.config.base import _
from spyder.py3compat import PY3
from spyder.py3compat import PY3, is_text_string
from spyder.utils.programs import check_version, is_stable_version


Expand Down Expand Up @@ -76,7 +76,7 @@ def start(self):
data = page.read()

# Needed step for python3 compatibility
if not isinstance(data, str):
if not is_text_string(data, str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also wrong, and it's what's making our tests to time out in master because checking if there's a new Spyder version is failing now.

data = data.decode()

data = json.loads(data)
Expand Down