Skip to content

Commit

Permalink
Increasing type coverage FTP (#11107)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlgruby committed Sep 23, 2020
1 parent b83507a commit bcdd3bb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions airflow/providers/ftp/hooks/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import datetime
import ftplib
import os.path
from typing import List, Optional
from typing import List, Optional, Any

from airflow.hooks.base_hook import BaseHook

Expand All @@ -42,7 +42,7 @@ def __init__(self, ftp_conn_id: str = 'ftp_default') -> None:
def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
if self.conn is not None:
self.close_conn()

Expand Down Expand Up @@ -183,7 +183,7 @@ def write_to_file_with_progress(data):
if is_path and output_handle:
output_handle.close()

def store_file(self, remote_full_path, local_full_path_or_buffer):
def store_file(self, remote_full_path: str, local_full_path_or_buffer: Any) -> None:
"""
Transfers a local file to the remote location.
Expand Down Expand Up @@ -248,15 +248,16 @@ def get_mod_time(self, path: str) -> datetime.datetime:
except ValueError:
return datetime.datetime.strptime(time_val, '%Y%m%d%H%M%S')

def get_size(self, path):
def get_size(self, path: str) -> Optional[int]:
"""
Returns the size of a file (in bytes)
:param path: remote file path
:type path: str
"""
conn = self.get_conn()
return conn.size(path)
size = conn.size(path)
return int(size) if size else None


class FTPSHook(FTPHook):
Expand Down

0 comments on commit bcdd3bb

Please sign in to comment.