[REM] *: remove various unused import shims

Before this commit, a lot of leftover import shims existed in the
codebase for py2-py3 compatibility, these are no longer needed since
Odoo 13.0+ doesn't support Python 2 anymore and is (finally) in EOL.

With this commit, these shims are dropped, making the code cleaner,
easier to read and with one less dependency.

Queue -> queue -> py2-py3 compatibility
xmlrpclib -> xmlrpc.client -> py2-py3 compatibility
ConfigParser -> configparser -> py2-py3 compatibility
itertools.izip_longest -> itertools.zip_longest -> py2-py3 compatibility
urllib -> urllib.request -> py2-py3 compatibility
__builtins__ -> builtins -> py2-py3 compatibility
_winreg -> winreg -> py2-py3 compatibility

mock -> unittest.mock -> merged into CPython

The debian/fedora packages and requirements.txt have been updated accordingly

closes odoo/odoo#44601

Related: odoo/enterprise#8141
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
Adrian Torres
2020-04-01 12:45:40 +00:00
parent c248594ee5
commit 5952928b42
23 changed files with 23 additions and 98 deletions
+1 -4
View File
@@ -1,10 +1,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import common
from odoo.exceptions import ValidationError
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch
from stdnum.eu import vat
@@ -13,10 +13,7 @@ import time
from threading import Lock
from usb import util
import urllib3
try:
from queue import Queue, Empty
except ImportError:
from Queue import Queue, Empty # pylint: disable=deprecated-module
from queue import Queue, Empty
from odoo import http, _
from odoo.addons.hw_proxy.controllers.main import drivers as old_drivers
+1 -4
View File
@@ -18,10 +18,7 @@ try:
except ImportError:
escpos = printer = None
try:
from queue import Queue
except ImportError:
from Queue import Queue # pylint: disable=deprecated-module
from queue import Queue
from threading import Thread, Lock
try:
+1 -5
View File
@@ -10,14 +10,10 @@ import email.policy
import dateutil
import pytz
import base64
try:
from xmlrpc import client as xmlrpclib
except ImportError:
import xmlrpclib
from lxml import etree
from datetime import datetime
from xmlrpc import client as xmlrpclib
from odoo import api, fields, models, tools, _
from odoo.exceptions import ValidationError, UserError
+1 -4
View File
@@ -16,15 +16,12 @@ import re
import socket
import time
import threading
try:
from xmlrpc import client as xmlrpclib
except ImportError:
import xmlrpclib
from collections import namedtuple
from email.message import EmailMessage
from lxml import etree
from werkzeug import urls
from xmlrpc import client as xmlrpclib
from odoo import _, api, exceptions, fields, models, tools, registry, SUPERUSER_ID
from odoo.exceptions import MissingError
@@ -3,11 +3,7 @@
from odoo.tests import common
from lxml import etree
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch
class TestMassMailingShortener(common.TransactionCase):
+1 -5
View File
@@ -1,12 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
try:
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest
import unittest
from itertools import zip_longest
from lxml import etree as ET, html
from lxml.html import builder as h
@@ -1,10 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch
import odoo
from odoo.tests import tagged
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from odoo.exceptions import AccessError
from unittest.mock import patch
from odoo.exceptions import AccessError
from odoo.tests.common import TransactionCase
from odoo.addons.crm.tests.common import TestCrmCommon
from odoo.addons.mail.tests.common import mail_new_test_user
@@ -1,10 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch
import odoo
from odoo.tests import tagged
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch
from odoo.addons.base.tests.common import TransactionCaseWithUserDemo, HttpCaseWithUserPortal
from odoo.tests import tagged
from odoo.tests.common import HttpCase, TransactionCase
-1
View File
@@ -28,7 +28,6 @@ Depends:
python3-libsass,
python3-lxml,
python3-mako,
python3-mock,
python3-passlib,
python3-polib,
python3-psutil,
+1 -4
View File
@@ -4,14 +4,11 @@ from __future__ import print_function
import os.path
import posixpath
import re
try:
from urllib.request import url2pathname # pylint: disable=deprecated-module
except ImportError:
from urllib import url2pathname # pylint: disable=deprecated-module
from docutils import nodes
from sphinx import addnodes, util, builders
from sphinx.locale import admonitionlabels
from urllib.request import url2pathname
def _parents(node):
@@ -1,10 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch
from odoo.addons.base.tests.common import SavepointCaseWithUserDemo
from odoo.tests import common
@@ -5,10 +5,7 @@ import logging
from odoo.tests import common
from odoo.cli.populate import Populate
from odoo.tools import mute_logger, populate
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch
_logger = logging.getLogger(__name__)
@@ -154,4 +151,4 @@ class TestPopulateMissing(common.TransactionCase):
if no_factory_fields:
_logger.info('Model %s has some undefined field: %s', model._name, no_factory_fields)
_logger.info('No populate factories defiend for %s', no_factory_models)
_logger.info('No populate factories defiend for %s', no_factory_models)
+1 -7
View File
@@ -6,18 +6,12 @@
from collections import defaultdict
from datetime import date, datetime, time
from operator import attrgetter
from xmlrpc.client import MAXINT
import itertools
import logging
import base64
import binascii
import pytz
try:
from xmlrpc.client import MAXINT
except ImportError:
#pylint: disable=bad-python3-import
from xmlrpclib import MAXINT
import psycopg2
from .tools import (
+1 -6
View File
@@ -12,12 +12,7 @@ import sys
import threading
import traceback
try:
from xmlrpc import client as xmlrpclib
except ImportError:
# pylint: disable=bad-python3-import
import xmlrpclib
from xmlrpc import client as xmlrpclib
import werkzeug.exceptions
import werkzeug.wrappers
+2 -10
View File
@@ -32,7 +32,9 @@ from datetime import datetime, date
from unittest.mock import patch
from decorator import decorator
from itertools import zip_longest as izip_longest
from lxml import etree, html
from xmlrpc import client as xmlrpclib
from odoo.models import BaseModel
from odoo.osv.expression import normalize_domain, TRUE_LEAF, FALSE_LEAF
@@ -40,22 +42,12 @@ from odoo.tools import float_compare, single_email_re
from odoo.tools.misc import find_in_path
from odoo.tools.safe_eval import safe_eval
try:
from itertools import zip_longest as izip_longest
except ImportError:
from itertools import izip_longest
try:
import websocket
except ImportError:
# chrome headless tests will be skipped
websocket = None
try:
from xmlrpc import client as xmlrpclib
except ImportError:
# pylint: disable=bad-python3-import
import xmlrpclib
import odoo
import pprint
+1 -5
View File
@@ -367,11 +367,7 @@ def _get_win_folder_from_registry(csidl_name):
registry for this guarantees us the correct answer for all CSIDL_*
names.
"""
try:
import winreg as _winreg
except ImportError:
# pylint: disable=bad-python3-import
import _winreg
import winreg as _winreg
shell_folder_name = {
"CSIDL_APPDATA": "AppData",
+1 -5
View File
@@ -1,11 +1,7 @@
#odoo.loggers.handlers. -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
try:
import configparser as ConfigParser
except ImportError:
import ConfigParser
import configparser as ConfigParser
import errno
import logging
import optparse
-1
View File
@@ -17,7 +17,6 @@ lxml==4.3.2 ; sys_platform != 'win32' and python_version >= '3.7'
lxml ; sys_platform == 'win32'
Mako==1.0.7
MarkupSafe==1.1.0
mock==2.0.0
num2words==0.5.6
ofxparse==0.19
passlib==1.7.1
-1
View File
@@ -35,7 +35,6 @@ RUN apt-get update -qq && \
python3-libsass \
python3-lxml \
python3-mako \
python3-mock \
python3-ofxparse \
python3-passlib \
python3-polib \
-1
View File
@@ -20,7 +20,6 @@ RUN dnf update -d 0 -e 0 -y && \
python3-lxml \
python3-mako \
python3-markupsafe \
python3-mock \
python3-num2words \
python3-ofxparse \
python3-passlib \