From 261bc043c95ca0865323f3220164dfc9207779fd Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 17 Apr 2020 23:12:20 +0530 Subject: [PATCH] thumbor: Replace comment type annotations with normal annotations. Run custom lint checks on thumbor files. --- tools/linter_lib/custom_check.py | 4 ---- zthumbor/loaders/helpers.py | 8 ++++---- zthumbor/loaders/zloader.py | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index c6636eca3f..4bb4dda8a7 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -329,10 +329,6 @@ python_rules = RuleList( 'good_lines': ['if my_django_model.id == 42', 'self.user_profile._meta.pk'], 'bad_lines': ['if my_django_model.pk == 42']}, {'pattern': r'^\s*#\s*type:', - 'exclude': { - # thumbor is (currently) python2 only - 'zthumbor/', - }, 'description': 'Comment-style function type annotation. Use Python3 style annotations instead.', }, {'pattern': r"\S\s*#\s*type:(?!\s*ignore)", diff --git a/zthumbor/loaders/helpers.py b/zthumbor/loaders/helpers.py index d85bb802e5..f3fa009066 100644 --- a/zthumbor/loaders/helpers.py +++ b/zthumbor/loaders/helpers.py @@ -28,8 +28,9 @@ if PRODUCTION: else: secrets_file.read(os.path.join(DEPLOY_ROOT, "zproject/dev-secrets.conf")) -def get_secret(key, default_value=None, development_only=False): - # type: (str, Optional[Any], bool) -> Optional[Any] +def get_secret( + key: str, default_value: Optional[Any] = None, development_only: bool = False, +) -> Optional[Any]: if development_only and PRODUCTION: return default_value if secrets_file.has_option('secrets', key): @@ -40,8 +41,7 @@ THUMBOR_EXTERNAL_TYPE = 'external' THUMBOR_S3_TYPE = 's3' THUMBOR_LOCAL_FILE_TYPE = 'local_file' -def separate_url_and_source_type(url): - # type: (Text) -> Tuple[Text, Text] +def separate_url_and_source_type(url: Text) -> Tuple[Text, Text]: THUMBNAIL_URL_PATT = re.compile('^(?P.+)/source_type/(?P.+)') matches = THUMBNAIL_URL_PATT.match(url) assert matches is not None diff --git a/zthumbor/loaders/zloader.py b/zthumbor/loaders/zloader.py index 91f1a8bae2..0bb255f048 100644 --- a/zthumbor/loaders/zloader.py +++ b/zthumbor/loaders/zloader.py @@ -17,15 +17,13 @@ from .helpers import ( ) -def get_not_found_result(): - # type: () -> LoaderResult +def get_not_found_result() -> LoaderResult: result = LoaderResult() result.error = LoaderResult.ERROR_NOT_FOUND result.successful = False return result -async def load(context, url): - # type: (Context, str) -> LoaderResult +async def load(context: Context, url: str) -> LoaderResult: source_type, encoded_url = separate_url_and_source_type(url) actual_url = base64.urlsafe_b64decode(urllib.parse.unquote(encoded_url)).decode('utf-8')