Skip to content

Commit 8ab88dc

Browse files
committed
types without django-stubs
1 parent 2e84d9b commit 8ab88dc

File tree

15 files changed

+50
-36
lines changed

15 files changed

+50
-36
lines changed

mypy.ini

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,30 @@ disallow_untyped_calls = False
5050
disallow_incomplete_defs = False
5151
disallow_untyped_defs = False
5252
warn_return_any = False
53+
disable_error_code = var-annotated,attr-defined
5354

5455
## django migrations are whatever
5556
[mypy-*.migrations.*]
5657
strict = False
57-
#disable_error_code = var-annotated,import-untyped,import-not-found
5858
disallow_subclassing_any = False
5959

6060
## tests are looser
6161
[mypy-tests.*]
6262
disallow_untyped_defs = False
6363

64-
## trove code (trying to be) well-annotated (but still uses django...)
64+
## trove code aiming to someday be well-annotated (except for the django...)
6565
[mypy-trove.*]
66-
disallow_subclassing_any = False
6766
disallow_untyped_decorators = False
6867
disallow_any_generics = False
6968
warn_return_any = False
70-
[mypy-trove.views.*]
69+
70+
[mypy-trove.views.*,trove.admin,trove.apps]
71+
disallow_subclassing_any = False
72+
disallow_untyped_defs = False
73+
disallow_incomplete_defs = False
74+
75+
[mypy-trove.models.*]
76+
disallow_subclassing_any = False
7177
disallow_untyped_defs = False
7278
disallow_incomplete_defs = False
79+
disable_error_code = var-annotated,attr-defined

share/admin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def source_(self, obj):
7676

7777
def enabled(self, obj):
7878
return not obj.disabled
79-
enabled.boolean = True # type: ignore[attr-defined]
79+
enabled.boolean = True
8080

8181
@admin.action(description='schedule re-derive of all cards for each selected source config')
8282
def schedule_derive(self, request, queryset):

share/admin/celery.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ def status_(self, obj):
100100
self.STATUS_COLORS.get(obj.status, 'black'),
101101
obj.status.title()
102102
)
103-
status_.short_description = 'Status' # type: ignore[attr-defined]
103+
status_.short_description = 'Status'
104104

105105
def meta_(self, obj):
106106
return pprint.pformat(obj.meta)
107-
meta_.short_description = 'Meta' # type: ignore[attr-defined]
107+
meta_.short_description = 'Meta'
108108

109109
def source_(self, obj):
110110
return obj.meta.get('source_config') or obj.meta.get('source')
111-
source_.short_description = 'Source' # type: ignore[attr-defined]
111+
source_.short_description = 'Source'
112112

113113
def retry(self, request, queryset):
114114
for task in queryset:
@@ -117,4 +117,4 @@ def retry(self, request, queryset):
117117
task.meta.get('kwargs', {}),
118118
task_id=str(task.task_id)
119119
)
120-
retry.short_description = 'Retry Tasks' # type: ignore[attr-defined]
120+
retry.short_description = 'Retry Tasks'

share/admin/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def link(self, instance):
5757
linked_obj = getattr(instance, field_name)
5858
return admin_link_html(linked_obj)
5959
link_field = '{}_link'.format(field_name)
60-
link.short_description = field_name.replace('_', ' ') # type: ignore[attr-defined]
60+
link.short_description = field_name.replace('_', ' ')
6161
setattr(cls, link_field, link)
6262
append_to_cls_property(cls, 'readonly_fields', link_field)
6363
append_to_cls_property(cls, 'exclude', field_name)
@@ -89,7 +89,7 @@ def links(self, instance: Model) -> str:
8989
))
9090
)
9191
links_field = f'{field_name}_links'
92-
links.short_description = field_name.replace('_', ' ') # type: ignore[attr-defined]
92+
links.short_description = field_name.replace('_', ' ')
9393
setattr(cls, links_field, links)
9494
append_to_cls_property(cls, 'readonly_fields', links_field)
9595
append_to_cls_property(cls, 'exclude', field_name)

share/models/fields.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,10 @@ def __init__(self, *args, object_hook=None, **kwargs):
4848

4949

5050
class DateTimeAwareJSONField(models.JSONField):
51-
def __init__(self, *args, encoder=None, decoder=None, **kwargs):
52-
return super().__init__(
53-
*args,
54-
**kwargs,
55-
encoder=DateTimeAwareJSONEncoder,
56-
decoder=DateTimeAwareJSONDecoder,
57-
)
51+
def __init__(self, *args, **kwargs):
52+
kwargs['encoder'] = DateTimeAwareJSONEncoder
53+
kwargs['decoder'] = DateTimeAwareJSONDecoder
54+
return super().__init__(*args, **kwargs)
5855

5956

6057
class ShareURLField(models.TextField):
@@ -69,10 +66,10 @@ def deconstruct(self):
6966
kwargs.pop('max_length', None)
7067
return name, path, args, kwargs
7168

72-
def formfield(self, **kwargs):
69+
def formfield(self, **kwargs): # type: ignore[override]
7370
# As with CharField, this will cause URL validation to be performed
7471
# twice.
75-
defaults = {
72+
defaults: dict = {
7673
'form_class': forms.URLField,
7774
}
7875
if self.null and self.unique:
@@ -89,7 +86,7 @@ class EncryptedJSONField(models.BinaryField):
8986
"""
9087
prefix = b'jwe:::'
9188

92-
def get_db_prep_value(self, input_json, **kwargs):
89+
def get_db_prep_value(self, input_json, **kwargs): # type: ignore[override]
9390
if not input_json:
9491
return None
9592

share/models/index_backfill.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def task__schedule_index_backfill(self, index_backfill_pk):
160160
_messenger = IndexMessenger(celery_app=self.app, index_strategys=[_index_strategy])
161161
_messagetype = _index_strategy.backfill_message_type
162162
assert _messagetype in _index_strategy.supported_message_types
163+
_target_queryset: models.QuerySet
163164
if _messagetype == MessageType.BACKFILL_INDEXCARD:
164165
_target_queryset = (
165166
trove_db.Indexcard.objects

share/search/index_strategy/elastic8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def compute_strategy_checksum(cls):
105105
return ChecksumIri.digest_json(
106106
checksumalgorithm_name='sha-256',
107107
salt=cls.__name__,
108-
raw_json=_current_json,
108+
raw_json=_current_json, # type: ignore[arg-type]
109109
)
110110

111111
# abstract method from IndexStrategy

share/search/index_strategy/trovesearch_denorm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131
)
3232
from trove.trovesearch.search_params import (
3333
CardsearchParams,
34-
Propertypath,
3534
SearchFilter,
3635
SearchText,
3736
ValueType,
3837
ValuesearchParams,
39-
is_globpath,
4038
)
4139
from trove.trovesearch.search_handle import (
4240
CardsearchHandle,
@@ -46,6 +44,10 @@
4644
ValuesearchHandle,
4745
ValuesearchResult,
4846
)
47+
from trove.util.propertypath import (
48+
is_globpath,
49+
Propertypath,
50+
)
4951
from trove.vocab import osfmap
5052
from trove.vocab.namespaces import OWL, RDF
5153
from . import _trovesearch_util as ts

share/search/messages.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import typing
88

99
from share.search import exceptions
10-
from share.util import chunked
1110

1211

1312
logger = logging.getLogger(__name__)
@@ -98,7 +97,11 @@ def compose_however(message_type: typing.Union[int, MessageType], target_id: int
9897
'''pass-thru to PreferedDaemonMessageSubclass.compose
9998
'''
10099
assert isinstance(target_id, int)
101-
return V3Message.compose(message_type, target_id)
100+
return V3Message.compose((
101+
MessageType.from_int(message_type)
102+
if isinstance(message_type, int)
103+
else message_type
104+
), target_id)
102105

103106
@classmethod
104107
def from_received_message(cls, kombu_message):
@@ -202,7 +205,7 @@ def compose(cls, message_type: MessageType, target_id: int) -> dict:
202205
}
203206

204207
@property
205-
def _message_twople(self) -> (int, int):
208+
def _message_twople(self) -> tuple[int, int]:
206209
return self.kombu_message.payload['m']
207210

208211
@property

trove/digestive_tract.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def ingest(
6565
expiration_date=expiration_date,
6666
)
6767
for _card in _extracted_cards:
68-
task__derive.delay(_card.id, urgent=urgent)
68+
task__derive.delay(_card.pk, urgent=urgent)
6969

7070

7171
@transaction.atomic
@@ -109,7 +109,7 @@ def sniff(
109109
_suid.focus_identifier = _focus_identifier
110110
_suid.save()
111111
else:
112-
if _suid.focus_identifier_id != _focus_identifier.id:
112+
if _suid.focus_identifier_id != _focus_identifier.pk:
113113
raise DigestiveError(f'suid focus_identifier should not change! suid={_suid}, focus changed from {_suid.focus_identifier} to {_focus_identifier}')
114114
return _suid
115115

@@ -249,7 +249,7 @@ def _expel_supplementary_descriptions(supplementary_rdf_queryset: QuerySet[trove
249249
_affected_indexcards.add(_supplement.indexcard)
250250
_supplement.delete()
251251
for _indexcard in _affected_indexcards:
252-
task__derive.delay(_indexcard.id)
252+
task__derive.delay(_indexcard.pk)
253253

254254

255255
### BEGIN celery tasks

0 commit comments

Comments
 (0)