Skip to content

Commit

Permalink
[AIRFLOW-4376] Remove all past library usage (apache#5247)
Browse files Browse the repository at this point in the history
  • Loading branch information
BasPH authored and potiuk committed May 7, 2019
1 parent 1755c35 commit c3a957b
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 27 deletions.
4 changes: 1 addition & 3 deletions airflow/contrib/hooks/bigquery_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
from copy import deepcopy
from six import iteritems

from past.builtins import basestring

from airflow import AirflowException
from airflow.contrib.hooks.gcp_api_base_hook import GoogleCloudBaseHook
from airflow.hooks.dbapi_hook import DbApiHook
Expand Down Expand Up @@ -1952,7 +1950,7 @@ def _bind_parameters(operation, parameters):
for (name, value) in iteritems(parameters):
if value is None:
string_parameters[name] = 'NULL'
elif isinstance(value, basestring):
elif isinstance(value, str):
string_parameters[name] = "'" + _escape(value) + "'"
else:
string_parameters[name] = str(value)
Expand Down
5 changes: 2 additions & 3 deletions airflow/contrib/hooks/ftp_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import ftplib
import os.path
from airflow.hooks.base_hook import BaseHook
from past.builtins import basestring


def mlsd(conn, path="", facts=None):
Expand Down Expand Up @@ -200,7 +199,7 @@ def write_to_file_with_progress(data):
"""
conn = self.get_conn()

is_path = isinstance(local_full_path_or_buffer, basestring)
is_path = isinstance(local_full_path_or_buffer, str)

# without a callback, default to writing to a user-provided file or
# file-like buffer
Expand Down Expand Up @@ -238,7 +237,7 @@ def store_file(self, remote_full_path, local_full_path_or_buffer):
"""
conn = self.get_conn()

is_path = isinstance(local_full_path_or_buffer, basestring)
is_path = isinstance(local_full_path_or_buffer, str)

if is_path:
input_handle = open(local_full_path_or_buffer, 'rb')
Expand Down
3 changes: 1 addition & 2 deletions airflow/hooks/dbapi_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# under the License.

from builtins import str
from past.builtins import basestring
from datetime import datetime
from contextlib import closing
from typing import Optional
Expand Down Expand Up @@ -144,7 +143,7 @@ def run(self, sql, autocommit=False, parameters=None):
:param parameters: The parameters to render the SQL query with.
:type parameters: mapping or iterable
"""
if isinstance(sql, basestring):
if isinstance(sql, str):
sql = [sql]

with closing(self.get_conn()) as conn:
Expand Down
3 changes: 1 addition & 2 deletions airflow/hooks/hive_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from tempfile import NamedTemporaryFile

import unicodecsv as csv
from past.builtins import basestring
from six.moves import zip

from airflow import configuration
Expand Down Expand Up @@ -794,7 +793,7 @@ def get_conn(self, schema=None):

def _get_results(self, hql, schema='default', fetch_size=None, hive_conf=None):
from pyhive.exc import ProgrammingError
if isinstance(hql, basestring):
if isinstance(hql, str):
hql = [hql]
previous_description = None
with contextlib.closing(self.get_conn(schema)) as conn, \
Expand Down
3 changes: 1 addition & 2 deletions airflow/hooks/oracle_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from airflow.hooks.dbapi_hook import DbApiHook
from builtins import str
from past.builtins import basestring
from datetime import datetime
import numpy

Expand Down Expand Up @@ -152,7 +151,7 @@ def insert_rows(self, table, rows, target_fields=None, commit_every=1000):
i += 1
lst = []
for cell in row:
if isinstance(cell, basestring):
if isinstance(cell, str):
lst.append("'" + str(cell).replace("'", "''") + "'")
elif cell is None:
lst.append('NULL')
Expand Down
3 changes: 1 addition & 2 deletions airflow/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from time import sleep

import six
from past.builtins import basestring
from sqlalchemy import (Column, Index, Integer, String, and_, func, not_, or_)
from sqlalchemy.exc import OperationalError
from sqlalchemy.orm.session import make_transient
Expand Down Expand Up @@ -715,7 +714,7 @@ def manage_slas(self, dag, session=None):
emails = set()
for task in dag.tasks:
if task.email:
if isinstance(task.email, basestring):
if isinstance(task.email, str):
emails |= set(get_email_address_list(task.email))
elif isinstance(task.email, (list, tuple)):
emails |= set(task.email)
Expand Down
2 changes: 1 addition & 1 deletion airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def generate_command(dag_id,
:param pool: the Airflow pool that the task should run in
:type pool: unicode
:param cfg_path: the Path to the configuration file
:type cfg_path: basestring
:type cfg_path: str
:return: shell command that can be used to run the task instance
"""
iso = execution_date.isoformat()
Expand Down
4 changes: 1 addition & 3 deletions airflow/sensors/named_hive_partition_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# specific language governing permissions and limitations
# under the License.

from past.builtins import basestring

from airflow.sensors.base_sensor_operator import BaseSensorOperator
from airflow.utils.decorators import apply_defaults

Expand Down Expand Up @@ -54,7 +52,7 @@ def __init__(self,
super().__init__(
poke_interval=poke_interval, *args, **kwargs)

if isinstance(partition_names, basestring):
if isinstance(partition_names, str):
raise TypeError('partition_names must be an array of strings')

self.metastore_conn_id = metastore_conn_id
Expand Down
4 changes: 1 addition & 3 deletions airflow/utils/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# specific language governing permissions and limitations
# under the License.

from past.builtins import basestring

import importlib
import os
import smtplib
Expand Down Expand Up @@ -124,7 +122,7 @@ def send_MIME_email(e_from, e_to, mime_msg, dryrun=False):


def get_email_address_list(address_string):
if isinstance(address_string, basestring):
if isinstance(address_string, str):
if ',' in address_string:
address_string = [address.strip() for address in address_string.split(',')]
elif ';' in address_string:
Expand Down
7 changes: 3 additions & 4 deletions airflow/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import psutil

from builtins import input
from past.builtins import basestring
from datetime import datetime
from functools import reduce
import os
Expand All @@ -44,7 +43,7 @@


def validate_key(k, max_length=250):
if not isinstance(k, basestring):
if not isinstance(k, str):
raise TypeError("The key has to be a string")
elif len(k) > max_length:
raise AirflowException(
Expand Down Expand Up @@ -104,7 +103,7 @@ def is_container(obj):
"""
Test if an object is a container (iterable) but not a string
"""
return hasattr(obj, '__iter__') and not isinstance(obj, basestring)
return hasattr(obj, '__iter__') and not isinstance(obj, str)


def as_tuple(obj):
Expand Down Expand Up @@ -232,7 +231,7 @@ def pprinttable(rows):
s += separator + '\n'

def f(t):
return "{}".format(t) if isinstance(t, basestring) else t
return "{}".format(t) if isinstance(t, str) else t

for line in rows:
s += pattern % tuple(f(t) for t in line) + '\n'
Expand Down
3 changes: 1 addition & 2 deletions airflow/www/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io

from builtins import str
from past.builtins import basestring

from pygments import highlight, lexers
from pygments.formatters import HtmlFormatter
Expand Down Expand Up @@ -317,7 +316,7 @@ def pygment_html_render(s, lexer=lexers.TextLexer):

def render(obj, lexer):
out = ""
if isinstance(obj, basestring):
if isinstance(obj, str):
out += pygment_html_render(obj, lexer)
elif isinstance(obj, (tuple, list)):
for i, s in enumerate(obj):
Expand Down

0 comments on commit c3a957b

Please sign in to comment.