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

Fix for Python 3.9/3.10: remove xml.etree.cElementTree #2846

Merged
merged 3 commits into from
May 24, 2020
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
5 changes: 1 addition & 4 deletions gensim/corpora/wikicorpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import signal
from pickle import PicklingError
# LXML isn't faster, so let's go with the built-in solution
try:
from xml.etree.cElementTree import iterparse
except ImportError:
from xml.etree.ElementTree import iterparse
from xml.etree.ElementTree import iterparse


from gensim import utils
Expand Down
11 changes: 4 additions & 7 deletions gensim/scripts/segment_wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@
import multiprocessing
import re
import sys
try:
from xml.etree import cElementTree as ET
except ImportError:
from xml.etree import ElementTree as ET
from xml.etree import ElementTree
from functools import partial

from gensim.corpora.wikicorpus import IGNORED_NAMESPACES, WikiCorpus, filter_wiki, find_interlinks, get_namespace, utils
Expand Down Expand Up @@ -186,7 +183,7 @@ def extract_page_xmls(f):
XML strings for page tags.

"""
elems = (elem for _, elem in ET.iterparse(f, events=("end",)))
elems = (elem for _, elem in ElementTree.iterparse(f, events=("end",)))

elem = next(elems)
namespace = get_namespace(elem.tag)
Expand All @@ -195,7 +192,7 @@ def extract_page_xmls(f):

for elem in elems:
if elem.tag == page_tag:
yield ET.tostring(elem)
yield ElementTree.tostring(elem)
# Prune the element tree, as per
# http://www.ibm.com/developerworks/xml/library/x-hiperfparse/
# except that we don't need to prune backlinks from the parent
Expand Down Expand Up @@ -224,7 +221,7 @@ def segment(page_xml, include_interlinks=False):
(Optionally) [(interlink_article, interlink_text), ...]).

"""
elem = ET.fromstring(page_xml)
elem = ElementTree.fromstring(page_xml)
filter_namespaces = ('0',)
namespace = get_namespace(elem.tag)
ns_mapping = {"ns": namespace}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ def run(self):
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Text Processing :: Linguistic',
Expand Down