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

Modernize the use of QRegExp to use QRegularExpression #22259

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 6 additions & 4 deletions spyder/plugins/editor/widgets/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
from packaging.version import parse
from qtpy import QT_VERSION
from qtpy.compat import to_qvariant
from qtpy.QtCore import (QEvent, QEventLoop, QRegExp, Qt, QTimer, QThread,
QUrl, Signal, Slot)
from qtpy.QtCore import (QEvent, QEventLoop, QRegularExpression, Qt, QTimer,
QThread, QUrl, Signal, Slot)
from qtpy.QtGui import (QColor, QCursor, QFont, QKeySequence, QPaintEvent,
QPainter, QMouseEvent, QTextCursor, QDesktopServices,
QKeyEvent, QTextDocument, QTextFormat, QTextOption,
Expand Down Expand Up @@ -2590,15 +2590,17 @@ def __find_first(self, text):
cursor = self.textCursor()
# Scanning whole document
cursor.movePosition(QTextCursor.Start)
regexp = QRegExp(r"\b%s\b" % QRegExp.escape(text), Qt.CaseSensitive)
regexp = QRegularExpression(
r"\b%s\b" % QRegularExpression.escape(text), Qt.CaseSensitive)
cursor = self.document().find(regexp, cursor, flags)
self.__find_first_pos = cursor.position()
return cursor

def __find_next(self, text, cursor):
"""Find next occurrence"""
flags = QTextDocument.FindCaseSensitively|QTextDocument.FindWholeWords
regexp = QRegExp(r"\b%s\b" % QRegExp.escape(text), Qt.CaseSensitive)
regexp = QRegularExpression(
r"\b%s\b" % QRegularExpression.escape(text), Qt.CaseSensitive)
cursor = self.document().find(regexp, cursor, flags)
if cursor.position() != self.__find_first_pos:
return cursor
Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/explorer/widgets/fileassociations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

# Third party imports
from qtpy.compat import getopenfilename
from qtpy.QtCore import QRegExp, QSize, Qt, Signal, Slot
from qtpy.QtGui import QCursor, QRegExpValidator
from qtpy.QtCore import QRegularExpression, QSize, Qt, Signal, Slot
from qtpy.QtGui import QCursor, QRegularExpressionValidator
from qtpy.QtWidgets import (QApplication, QDialog, QDialogButtonBox,
QHBoxLayout, QLabel, QLineEdit,
QListWidget, QListWidgetItem, QPushButton,
Expand Down Expand Up @@ -83,7 +83,7 @@ def set_regex_validation(self, regex):
"""Set the regular expression to validate content."""
self._regex = regex
self._reg = re.compile(regex, re.IGNORECASE)
validator = QRegExpValidator(QRegExp(regex))
validator = QRegularExpressionValidator(QRegularExpression(regex))
self.lineedit.setValidator(validator)

def text(self):
Expand Down
7 changes: 4 additions & 3 deletions spyder/plugins/preferences/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from qtpy import API
from qtpy.compat import (getexistingdirectory, getopenfilename, from_qvariant,
to_qvariant)
from qtpy.QtCore import Qt, Signal, Slot, QRegExp
from qtpy.QtGui import QColor, QRegExpValidator, QTextOption
from qtpy.QtCore import Qt, Signal, Slot, QRegularExpression
from qtpy.QtGui import QColor, QRegularExpressionValidator, QTextOption
from qtpy.QtWidgets import (QButtonGroup, QCheckBox, QComboBox, QDoubleSpinBox,
QFileDialog, QFontComboBox, QGridLayout, QGroupBox,
QHBoxLayout, QLabel, QLineEdit, QMessageBox,
Expand Down Expand Up @@ -494,7 +494,8 @@ def create_lineedit(self, text, option, default=NoDefault,
if tip:
edit.setToolTip(tip)
if regex:
edit.setValidator(QRegExpValidator(QRegExp(regex)))
edit.setValidator(
QRegularExpressionValidator(QRegularExpression(regex)))
if placeholder:
edit.setPlaceholderText(placeholder)
self.lineedits[edit] = (section, option, default)
Expand Down
9 changes: 5 additions & 4 deletions spyder/widgets/helperwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# Third party imports
import qstylizer.style
from qtpy import PYQT5
from qtpy.QtCore import QPoint, QRegExp, QSize, QSortFilterProxyModel, Qt
from qtpy.QtCore import (QPoint, QRegularExpression, QSize,
QSortFilterProxyModel, Qt)
from qtpy.QtGui import (QAbstractTextDocumentLayout, QColor, QFontMetrics,
QPainter, QRegExpValidator, QTextDocument, )
QPainter, QRegularExpressionValidator, QTextDocument)
from qtpy.QtWidgets import (QApplication, QCheckBox, QLineEdit, QMessageBox,
QSpacerItem, QStyle, QStyledItemDelegate,
QStyleOptionFrame, QStyleOptionViewItem,
Expand Down Expand Up @@ -345,8 +346,8 @@ def __init__(self, parent, callback=None, main=None,
self.main = main

# Widget setup
regex = QRegExp(regex_base + "{100}")
self.setValidator(QRegExpValidator(regex))
regex = QRegularExpression(regex_base + "{100}")
self.setValidator(QRegularExpressionValidator(regex))

# Signals
if callback:
Expand Down
Loading