Skip to content

Commit a78469d

Browse files
author
Alan Christie
committed
refactor: More style changes (to comply with mypy)
1 parent cd0d520 commit a78469d

10 files changed

+38
-36
lines changed

api/security.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
# pylint: skip-file
12
import logging
23
import os
34
import time
45

56
from pathlib import Path
6-
from typing import Any
77

88
from wsgiref.util import FileWrapper
99
from django.http import Http404
@@ -102,12 +102,6 @@ def get_conn():
102102

103103

104104
class ISpyBSafeQuerySet(viewsets.ReadOnlyModelViewSet):
105-
def __init__(self, **kwargs: Any) -> None:
106-
super().__init__(**kwargs)
107-
self.request = None
108-
self.filter_permissions = None
109-
self.queryset = None
110-
111105
def get_queryset(self):
112106
"""
113107
Optionally restricts the returned purchases to a given proposals

docs/source/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# List of patterns, relative to source directory, that match files and
4444
# directories to ignore when looking for source files.
4545
# This pattern also affects html_static_path and html_extra_path.
46-
exclude_patterns = []
46+
exclude_patterns = [] # type: ignore
4747

4848

4949
# -- Options for HTML output -------------------------------------------------

fragalysis/settings.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,11 @@
280280
if os.environ.get("BUILD_XCDB") == 'yes':
281281
DATABASES["xchem_db"] = {
282282
"ENGINE": 'django.db.backends.postgresql',
283-
"NAME": os.environ.get("XCHEM_NAME"),
284-
"USER": os.environ.get("XCHEM_USER"),
285-
"PASSWORD": os.environ.get("XCHEM_PASSWORD"),
286-
"HOST": os.environ.get("XCHEM_HOST"),
287-
"PORT": os.environ.get("XCHEM_PORT"),
283+
"NAME": os.environ.get("XCHEM_NAME", ""),
284+
"USER": os.environ.get("XCHEM_USER", ""),
285+
"PASSWORD": os.environ.get("XCHEM_PASSWORD", ""),
286+
"HOST": os.environ.get("XCHEM_HOST", ""),
287+
"PORT": os.environ.get("XCHEM_PORT", ""),
288288
}
289289

290290
if CHEMCENTRAL_DB_NAME != "UNKOWN":

viewer/cset_upload.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,13 @@
3737

3838
def dataType(a_str: str) -> str:
3939
lean_str = a_str.strip()
40-
if len(lean_str) == 0:
40+
if not lean_str:
4141
return 'BLANK'
42+
4243
try:
4344
t = ast.literal_eval(lean_str)
44-
45-
except ValueError:
46-
return 'TEXT'
47-
except SyntaxError:
45+
except (ValueError, SyntaxError):
4846
return 'TEXT'
49-
5047
else:
5148
if type(t) in [int, int, float, bool]:
5249
if t in [
@@ -72,6 +69,9 @@ def dataType(a_str: str) -> str:
7269
return 'INT'
7370
if type(t) is float:
7471
return 'FLOAT'
72+
73+
# Can't get here?
74+
assert False
7575
else:
7676
return 'TEXT'
7777

viewer/discourse.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
discourse.py Functions for to send and retrieve posts to/fraom the discourse platform.
33
"""
44
import os
5+
from typing import Tuple
6+
57
from pydiscourse import DiscourseClient
68
from django.conf import settings
79
from viewer.models import DiscourseCategory, DiscourseTopic
@@ -10,15 +12,16 @@
1012
logger = logging.getLogger(__name__)
1113

1214

13-
def get_user(client, username):
14-
"""Call discourse API users to retreive user by username."""
15+
def get_user(client, username) -> Tuple[bool, str, int]:
16+
"""Call discourse API users to retrieve user by username."""
1517
logger.info('+ discourse.get_user')
16-
error = False
17-
error_message = ''
18-
user = 0
18+
19+
error: bool = False
20+
error_message: str = ''
21+
user: int = 0
1922

2023
try:
21-
user = client.user(username)
24+
user_record = client.user(username)
2225
except Exception as e:
2326
# User is not known in Discourse or there is a failure accessing Discourse.
2427
logger.error('discourse.get_user', exc_info=e)
@@ -33,7 +36,7 @@ def get_user(client, username):
3336
else:
3437
error_message = 'Please check Discourse Host parameter for Fragalysis'
3538
else:
36-
user = user['id']
39+
user = user_record['id']
3740

3841
logger.info('- discourse.get_user')
3942
return error, error_message, user

viewer/migrations/0018_merge_20231109_1252.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ class Migration(migrations.Migration):
88
('viewer', '0017_alter_experimentupload_message'),
99
]
1010

11-
operations = []
11+
operations = [] # type: ignore

viewer/models.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dataclasses import dataclass
22
import uuid
33
import logging
4+
from typing import List
45

56
from django.contrib.auth.models import User
67
from django.db import models
@@ -457,13 +458,13 @@ def get_vectors(
457458
cmpd_id=None,
458459
vector_type=None,
459460
number=None,
460-
):
461+
) -> List[Vector3d]:
461462
"""Get the vectors for a given molecule
462463
463464
:param mols: the Django molecules to get them from
464465
:return: None
465466
"""
466-
result = []
467+
result: List[Vector3d] = []
467468
# pk checks and later continure statements are doing filtering
468469
# - as this is not going through the usual django_filter
469470
# machinery, it needs a different approach

viewer/squonk_job_file_transfer.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import urllib.parse
55
import os
6+
from typing import Dict, List, Tuple
67

78
from django.conf import settings
89
from rest_framework import status
@@ -109,7 +110,9 @@ def process_file_transfer(auth_token, job_transfer_id):
109110
raise RuntimeError(msg)
110111

111112

112-
def validate_file_transfer_files(request):
113+
def validate_file_transfer_files(
114+
request,
115+
) -> Tuple[Dict[str, str], List[SiteObservation], List[ComputedMolecule]]:
113116
"""Check the request and return a list of proteins and/or computed molecule objects
114117
115118
Args:
@@ -119,9 +122,9 @@ def validate_file_transfer_files(request):
119122
list of validated proteins (SiteObservation)
120123
list of validated computed molecules (ComputedMolecule)
121124
"""
122-
error = {}
123-
proteins = []
124-
compounds = []
125+
error: Dict[str, str] = {}
126+
proteins: List[SiteObservation] = []
127+
compounds: List[ComputedMolecule] = []
125128

126129
if request.data['proteins']:
127130
# Get first part of protein code

viewer/target_set_upload.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
import logging
99
import sys
10+
from typing import Any, Dict
1011

1112
# import json
1213
import os
@@ -801,7 +802,7 @@ def validate_target(new_data_folder, target_name, proposal_ref):
801802
# Don't need
802803
del proposal_ref
803804

804-
validate_dict = {'Location': [], 'Error': [], 'Line number': []}
805+
validate_dict: Dict[str, Any] = {'Location': [], 'Error': [], 'Line number': []}
805806

806807
# Check if there is any data to process
807808
target_path = os.path.join(new_data_folder, target_name)

viewer/tests/test_loader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from viewer.models import QuatAssembly
2020

2121

22-
test_mpro_v1 = Path(__file__).absolute().parent.joinpath("Mpro-v1-zero.tgz")
23-
test_mpro_v2 = Path(__file__).absolute().parent.joinpath("Mpro-v2-zero.tgz")
22+
test_mpro_v1 = str(Path(__file__).absolute().parent.joinpath("Mpro-v1-zero.tgz"))
23+
test_mpro_v2 = str(Path(__file__).absolute().parent.joinpath("Mpro-v2-zero.tgz"))
2424

2525

2626
class LoaderTests(TestCase):

0 commit comments

Comments
 (0)