From 66c0155508bbebd090d31f7bb9be3ff730c7af93 Mon Sep 17 00:00:00 2001
From: PrimozGodec
Date: Fri, 12 Jan 2024 10:03:50 +0100
Subject: [PATCH] Use enum2int from Orange
---
orangecontrib/text/widgets/owkeywords.py | 2 +-
.../text/widgets/owscoredocuments.py | 2 +-
orangecontrib/text/widgets/utils/__init__.py | 21 -------------------
.../text/widgets/utils/tests/test_utils.py | 18 ----------------
requirements.txt | 2 +-
tox.ini | 2 +-
6 files changed, 4 insertions(+), 43 deletions(-)
delete mode 100644 orangecontrib/text/widgets/utils/tests/test_utils.py
diff --git a/orangecontrib/text/widgets/owkeywords.py b/orangecontrib/text/widgets/owkeywords.py
index c2f6b85e6..a5df964a8 100644
--- a/orangecontrib/text/widgets/owkeywords.py
+++ b/orangecontrib/text/widgets/owkeywords.py
@@ -15,6 +15,7 @@
from Orange.widgets import gui
from Orange.widgets.settings import DomainContextHandler, ContextSetting, \
Setting
+from Orange.widgets.utils import enum2int
from Orange.widgets.utils.concurrent import ConcurrentWidgetMixin, TaskState
from Orange.widgets.utils.itemmodels import PyTableModel, TableModel
from Orange.widgets.widget import Input, Output, OWWidget, Msg
@@ -23,7 +24,6 @@
from orangecontrib.text.keywords import ScoringMethods, AggregationMethods, \
YAKE_LANGUAGE_MAPPING, RAKE_LANGUAGES
from orangecontrib.text.preprocess import BaseNormalizer
-from orangecontrib.text.widgets.utils import enum2int
from orangecontrib.text.widgets.utils.words import create_words_table, \
WORDS_COLUMN_NAME
diff --git a/orangecontrib/text/widgets/owscoredocuments.py b/orangecontrib/text/widgets/owscoredocuments.py
index 649a6d2bb..9637ba2ca 100644
--- a/orangecontrib/text/widgets/owscoredocuments.py
+++ b/orangecontrib/text/widgets/owscoredocuments.py
@@ -24,6 +24,7 @@
from Orange.data.util import get_unique_names
from Orange.util import wrap_callback
from Orange.widgets.settings import ContextSetting, PerfectDomainContextHandler, Setting
+from Orange.widgets.utils import enum2int
from Orange.widgets.utils.annotated_data import create_annotated_table, add_columns
from Orange.widgets.utils.concurrent import ConcurrentWidgetMixin, TaskState
from Orange.widgets.utils.itemmodels import PyTableModel, TableModel
@@ -36,7 +37,6 @@
from orangecontrib.text import Corpus
from orangecontrib.text.preprocess import BaseNormalizer, NGrams, BaseTokenFilter
from orangecontrib.text.vectorization.sbert import SBERT
-from orangecontrib.text.widgets.utils import enum2int
from orangecontrib.text.widgets.utils.words import create_words_table
diff --git a/orangecontrib/text/widgets/utils/__init__.py b/orangecontrib/text/widgets/utils/__init__.py
index eba92aea3..c7b2a6b05 100644
--- a/orangecontrib/text/widgets/utils/__init__.py
+++ b/orangecontrib/text/widgets/utils/__init__.py
@@ -1,24 +1,3 @@
-from enum import IntEnum, Enum
-from typing import Union
-
from .decorators import *
from .widgets import *
from .concurrent import asynchronous
-
-
-def enum2int(enum: Union[Enum, IntEnum]) -> int:
- """
- PyQt5 uses IntEnum like object for settings, for example SortOrder while
- PyQt6 uses Enum. PyQt5's IntEnum also does not support value attribute.
- This function transform both settings objects to int.
-
- Parameters
- ----------
- enum
- IntEnum like object or Enum object with Qt's settings
-
- Returns
- -------
- Settings transformed to int
- """
- return int(enum) if isinstance(enum, int) else enum.value
diff --git a/orangecontrib/text/widgets/utils/tests/test_utils.py b/orangecontrib/text/widgets/utils/tests/test_utils.py
deleted file mode 100644
index 90f100a5b..000000000
--- a/orangecontrib/text/widgets/utils/tests/test_utils.py
+++ /dev/null
@@ -1,18 +0,0 @@
-import unittest
-from datetime import datetime
-
-
-class TestEnum2Int(unittest.TestCase):
- def test_remove_enum2int(self):
- """
- Happy new year 2024. When this test start to fail:
- - remove enum2int from orangecontrib.text.widgets.utils.__init__
- - change imports to Orange's enum2int in widget that use it
- - remove this test
- - depend orange3-text on orange 3.35
- """
- self.assertLess(datetime.today(), datetime(2024, 1, 1))
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/requirements.txt b/requirements.txt
index ccdc4fa48..36c489f1d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -10,7 +10,7 @@ lemmagen3
nltk>=3.0.5 # TweetTokenizer introduced in 3.0.5
numpy
odfpy>=1.3.5
-Orange3 >=3.34.0
+Orange3 >=3.35.0
orange-widget-base >=4.20.0
orange-canvas-core
owlready2
diff --git a/tox.ini b/tox.ini
index df23983de..0898b7ba8 100644
--- a/tox.ini
+++ b/tox.ini
@@ -25,7 +25,7 @@ deps =
{env:PYQT_PYPI_NAME:PyQt5}=={env:PYQT_PYPI_VERSION:5.15.*}
{env:WEBENGINE_PYPI_NAME:PyQtWebEngine}=={env:WEBENGINE_PYPI_VERSION:5.15.*}
oldest: scikit-learn==1.0.1
- oldest: orange3==3.34.0
+ oldest: orange3==3.35.0
oldest: orange-canvas-core==0.1.30
oldest: orange-widget-base==4.20.0
oldest: pandas==1.4.0