From 1f97984340b392545a7f2cfb0a055d70ea7bfabf Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 9 May 2025 11:46:33 +0100 Subject: [PATCH] Ensure that function arguments with default values have a type --- follow.py | 6 +++--- person.py | 2 +- posts.py | 5 +++-- tests.py | 8 ++++++++ utils.py | 6 +++--- webapp_utils.py | 4 ++-- webapp_welcome.py | 2 +- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/follow.py b/follow.py index 41c7c1dc6..20173c554 100644 --- a/follow.py +++ b/follow.py @@ -401,7 +401,7 @@ def clear_followers(base_dir: str, nickname: str, domain: str) -> None: def _get_no_of_follows(base_dir: str, nickname: str, domain: str, - follow_file='following.txt') -> int: + follow_file: str = 'following.txt') -> int: """Returns the number of follows or followers """ # only show number of followers to authenticated @@ -444,8 +444,8 @@ def get_no_of_followers(base_dir: str, nickname: str, domain: str) -> int: def get_following_feed(base_dir: str, domain: str, port: int, path: str, http_prefix: str, authorized: bool, - follows_per_page=12, - follow_file='following') -> {}: + follows_per_page: int = 12, + follow_file: str = 'following') -> {}: """Returns the following and followers feeds from GET requests. This accesses the following.txt or followers.txt and builds a collection. """ diff --git a/person.py b/person.py index b2aead779..d0a00d518 100644 --- a/person.py +++ b/person.py @@ -696,7 +696,7 @@ def clear_person_qrcodes(base_dir: str) -> None: def save_person_qrcode(base_dir: str, nickname: str, domain: str, qrcode_domain: str, - port: int, scale=6) -> None: + port: int, scale: int = 6) -> None: """Saves a qrcode image for the handle of the person This helps to transfer onion or i2p handles to a mobile device """ diff --git a/posts.py b/posts.py index f4d2f616d..7b2fb4d3f 100644 --- a/posts.py +++ b/posts.py @@ -200,7 +200,8 @@ def is_moderator(base_dir: str, nickname: str) -> bool: def no_of_followers_on_domain(base_dir: str, handle: str, - domain: str, follow_file='followers.txt') -> int: + domain: str, + follow_file: str = 'followers.txt') -> int: """Returns the number of followers of the given handle from the given domain """ @@ -5679,7 +5680,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str, base_dir: str, boxname: str, archive_dir: str, recent_posts_cache: {}, - max_posts_in_box=32000) -> None: + max_posts_in_box: int = 32000) -> None: """Retain a maximum number of posts within the given box Move any others to an archive directory """ diff --git a/tests.py b/tests.py index 5252bc643..573ee8366 100644 --- a/tests.py +++ b/tests.py @@ -5673,11 +5673,19 @@ def _check_self_variables(mod_name: str, method_name: str, def _check_method_args(mod_name: str, method_name: str, method_args: []) -> bool: """Tests that method arguments are not CamelCase + and that arguments with default values have types """ + exclude_modules = ['pyjsonld'] for arg_str in method_args: if ':' in arg_str: arg_str = arg_str.split(':')[0] if '=' in arg_str: + # is a type given? + if mod_name not in exclude_modules and \ + ':' not in arg_str and '=None' not in arg_str: + print(mod_name + ', ' + method_name + ', ' + arg_str + + ', = in function argument without type') + return False arg_str = arg_str.split('=')[0] arg_str = arg_str.strip() if arg_str != arg_str.lower(): diff --git a/utils.py b/utils.py index 2438e8b73..72c59270f 100644 --- a/utils.py +++ b/utils.py @@ -1102,7 +1102,7 @@ def get_config_param(base_dir: str, variable_name: str) -> str: def get_followers_list(base_dir: str, nickname: str, domain: str, - follow_file='following.txt') -> []: + follow_file: str = 'following.txt') -> []: """Returns a list of followers for the given account """ filename = acct_dir(base_dir, nickname, domain) + '/' + follow_file @@ -1126,7 +1126,7 @@ def get_followers_list(base_dir: str, def get_followers_of_person(base_dir: str, nickname: str, domain: str, - follow_file='following.txt') -> []: + follow_file: str = 'following.txt') -> []: """Returns a list containing the followers of the given person Used by the shared inbox to know who to send incoming mail to """ @@ -3135,7 +3135,7 @@ def _actor_in_searchable_by(searchable_by: str, following_list: []) -> bool: def search_box_posts(base_dir: str, nickname: str, domain: str, search_str: str, max_results: int, - box_name='outbox') -> []: + box_name: str = 'outbox') -> []: """Search your posts and return a list of the filenames containing matching strings """ diff --git a/webapp_utils.py b/webapp_utils.py index 15833b221..70b5b4632 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -723,7 +723,7 @@ def get_right_image_file(base_dir: str, def html_header_with_external_style(css_filename: str, instance_title: str, metadata: str, preload_images: [], - lang='en') -> str: + lang: str = 'en') -> str: if metadata is None: metadata = '' css_file = '/' + css_filename.split('/')[-1] @@ -768,7 +768,7 @@ def html_header_with_external_style(css_filename: str, instance_title: str, def html_header_with_person_markup(css_filename: str, instance_title: str, actor_json: {}, city: str, content_license_url: str, - lang='en') -> str: + lang: str = 'en') -> str: """html header which includes person markup https://schema.org/Person """ diff --git a/webapp_welcome.py b/webapp_welcome.py index aba2b4173..9e51327a6 100644 --- a/webapp_welcome.py +++ b/webapp_welcome.py @@ -48,7 +48,7 @@ def welcome_screen_is_complete(base_dir: str, def html_welcome_screen(base_dir: str, nickname: str, language: str, translate: {}, theme_name: str, - curr_screen='welcome') -> str: + curr_screen: str = 'welcome') -> str: """Returns the welcome screen """ # set a custom background for the welcome screen