changeset 8851:05406c312342

pytype: add Python type annotations where necessary to guide pytype Mute pytype warnings: File "kallithea/lib/auth.py", line 142, in _cached_perms_data: No attribute 'DEFAULT_USER_ID' on module 'kallithea' [module-attr] File "kallithea/lib/vcs/backends/base.py", line 73, in ...: No attribute '...' on BaseRepository [attribute-error] File "kallithea/lib/vcs/backends/base.py", line 405, in ...: No attribute '...' on BaseChangeset [attribute-error] File "kallithea/tests/api/api_base.py", line 2397, in test_api_get_changeset: No attribute 'TEST_REVISION' on _BaseTestApi [attribute-error] File "kallithea/tests/api/api_base.py", line 2445, in test_api_get_pullrequest: No attribute 'TEST_PR_DST' on _BaseTestApi [attribute-error] File "kallithea/tests/api/api_base.py", line 2445, in test_api_get_pullrequest: No attribute 'TEST_PR_SRC' on _BaseTestApi [attribute-error] File "kallithea/tests/api/api_base.py", line 2467, in test_api_get_pullrequest: No attribute 'TEST_PR_REVISIONS' on _BaseTestApi [attribute-error] File "kallithea/tests/api/api_base.py", line 67, in api_call: No attribute 'app' on _BaseTestApi [attribute-error] File "kallithea/tests/base.py", line 154, in log_user: No attribute 'app' on TestController [attribute-error] File "kallithea/tests/base.py", line 169, in _get_logged_user: No attribute '_logged_username' on TestController [attribute-error]
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 14 Jan 2021 21:44:53 +0100
parents 755b2c66b462
children 252b86664549
files kallithea/__init__.py kallithea/lib/vcs/backends/base.py kallithea/tests/api/api_base.py kallithea/tests/base.py scripts/deps.py
diffstat 5 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/__init__.py	Tue Aug 18 22:25:45 2020 +0200
+++ b/kallithea/__init__.py	Thu Jan 14 21:44:53 2021 +0100
@@ -44,6 +44,7 @@
 
 CELERY_APP = celery.Celery()  # needed at import time but is lazy and can be configured later
 
+DEFAULT_USER_ID: int  # set by setup_configuration
 CONFIG = {}  # set to tg.config when TG app is initialized and calls app_cfg
 
 # URL prefix for non repository related links - must start with `/`
--- a/kallithea/lib/vcs/backends/base.py	Tue Aug 18 22:25:45 2020 +0200
+++ b/kallithea/lib/vcs/backends/base.py	Thu Jan 14 21:44:53 2021 +0100
@@ -11,6 +11,7 @@
 
 import datetime
 import itertools
+from typing import Sequence
 
 from kallithea.lib.vcs.backends import get_backend
 from kallithea.lib.vcs.conf import settings
@@ -51,8 +52,12 @@
         ``tags``
             tags as list of changesets
     """
-    scm = None
-    DEFAULT_BRANCH_NAME = None
+    DEFAULT_BRANCH_NAME: str  # assigned in subclass
+    scm: str  # assigned in subclass
+    path: str  # assigned in subclass __init__
+    revisions: Sequence[str]  # LazyProperty in subclass
+    _empty: bool  # property in subclass
+
     EMPTY_CHANGESET = '0' * 40
 
     def __init__(self, repo_path, create=False, **kwargs):
@@ -367,6 +372,9 @@
             otherwise; trying to access this attribute while there is no
             changesets would raise ``EmptyRepositoryError``
     """
+    message: str  # LazyProperty in subclass
+    date: datetime.datetime  # LazyProperty in subclass
+
     def __str__(self):
         return '<%s at %s:%s>' % (self.__class__.__name__, self.revision,
             self.short_id)
--- a/kallithea/tests/api/api_base.py	Tue Aug 18 22:25:45 2020 +0200
+++ b/kallithea/tests/api/api_base.py	Thu Jan 14 21:44:53 2021 +0100
@@ -20,9 +20,11 @@
 import random
 import re
 import string
+from typing import Sized
 
 import mock
 import pytest
+from webtest import TestApp
 
 from kallithea.lib import ext_json
 from kallithea.lib.auth import AuthUser
@@ -86,8 +88,14 @@
 
 
 class _BaseTestApi(object):
-    REPO = None
-    REPO_TYPE = None
+    app: TestApp  # assigned by app_fixture in subclass TestController mixin
+    # assigned in subclass:
+    REPO: str
+    REPO_TYPE: str
+    TEST_REVISION: str
+    TEST_PR_SRC: str
+    TEST_PR_DST: str
+    TEST_PR_REVISIONS: Sized
 
     @classmethod
     def setup_class(cls):
--- a/kallithea/tests/base.py	Tue Aug 18 22:25:45 2020 +0200
+++ b/kallithea/tests/base.py	Thu Jan 14 21:44:53 2021 +0100
@@ -138,6 +138,8 @@
 
 class TestController(object):
     """Pytest-style test controller"""
+    app: TestApp  # assigned by app_fixture
+    _logged_username: str  # assigned by log_user
 
     # Note: pytest base classes cannot have an __init__ method
 
--- a/scripts/deps.py	Tue Aug 18 22:25:45 2020 +0200
+++ b/scripts/deps.py	Thu Jan 14 21:44:53 2021 +0100
@@ -93,6 +93,7 @@
 traceback
 traitlets
 types
+typing
 urllib
 urlobject
 uuid