Skip to content

Commit

Permalink
[AIRFLOW-4198] Remove all try/import compatibility imports (apache#5091)
Browse files Browse the repository at this point in the history
  • Loading branch information
BasPH authored and potiuk committed May 5, 2019
1 parent 97ad71c commit 7f4d092
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 39 deletions.
8 changes: 3 additions & 5 deletions airflow/contrib/hooks/qubole_check_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@
# specific language governing permissions and limitations
# under the License.
#

from io import StringIO

from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.contrib.hooks.qubole_hook import QuboleHook
from airflow.exceptions import AirflowException
from qds_sdk.commands import Command

try:
from cStringIO import StringIO
except ImportError:
from io import StringIO


COL_DELIM = '\t'
ROW_DELIM = '\r\n'
Expand Down
13 changes: 4 additions & 9 deletions airflow/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@
# specific language governing permissions and limitations
# under the License.
#
import os

# inspect.signature is only available in Python 3. funcsigs.signature is
# a backport.
try:
import inspect
signature = inspect.signature
except AttributeError:
import funcsigs
signature = funcsigs.signature
import inspect
import os

from copy import copy
from functools import wraps

from airflow import settings
from airflow.exceptions import AirflowException

signature = inspect.signature


def apply_defaults(func):
"""
Expand Down
7 changes: 1 addition & 6 deletions dev/airflow-pr
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ import re
import subprocess
import sys
import textwrap

# Python 3 compatibility
try:
import urllib2 as urllib
except ImportError:
import urllib.request as urllib
import urllib.request as urllib

try:
import click
Expand Down
6 changes: 2 additions & 4 deletions tests/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
try:
from unittest import mock # noqa: F401
except ImportError:
import mock # type: ignore # noqa: F401

from unittest import mock # noqa: F401

patch = mock.patch
Mock = mock.Mock
Expand Down
6 changes: 1 addition & 5 deletions tests/contrib/hooks/test_gcp_api_base_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import os
import unittest
from io import StringIO

from parameterized import parameterized
from google.api_core.exceptions import RetryError, AlreadyExists
Expand All @@ -36,11 +37,6 @@
from airflow.hooks.base_hook import BaseHook
from tests.compat import mock

try:
from StringIO import StringIO
except ImportError:
from io import StringIO


default_creds_available = True
default_project = None
Expand Down
5 changes: 1 addition & 4 deletions tests/contrib/hooks/test_grpc_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
from io import StringIO

from airflow import configuration
from airflow.exceptions import AirflowConfigException
Expand Down
7 changes: 1 addition & 6 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import mock
import multiprocessing
import os
import pickle # type: ignore
import re
import signal
import sqlalchemy
Expand Down Expand Up @@ -75,12 +76,6 @@
TEST_DAG_ID = 'unit_tests'
EXAMPLE_DAG_DEFAULT_DATE = days_ago(2)

try:
import cPickle as pickle
except ImportError:
# Python 3
import pickle # type: ignore


class OperatorSubclass(BaseOperator):
"""
Expand Down

0 comments on commit 7f4d092

Please sign in to comment.