22
22
import re
23
23
from typing import Any , Optional
24
24
25
- from google .cloud import ndb
25
+ from google .cloud import ndb # type: ignore
26
26
27
27
from framework import rediscache
28
28
from framework import users
@@ -205,7 +205,7 @@ def format_for_template(self, version=2) -> dict[str, Any]:
205
205
self .migrate_views ()
206
206
logging .info ('In format_for_template for %s' ,
207
207
repr (self )[:settings .MAX_LOG_LINE ])
208
- d = self .to_dict ()
208
+ d : dict [ str , Any ] = self .to_dict ()
209
209
is_released = self .impl_status_chrome in RELEASE_IMPL_STATES
210
210
d ['is_released' ] = is_released
211
211
@@ -494,7 +494,8 @@ def filter_unlisted(self, feature_list: list[dict]) -> list[dict]:
494
494
495
495
@classmethod
496
496
def get_by_ids (
497
- self , feature_ids : list [int ], update_cache : bool = False ) -> list [dict ]:
497
+ self , feature_ids : list [int ],
498
+ update_cache : bool = False ) -> list [dict [str , Any ]]:
498
499
"""Return a list of JSON dicts for the specified features.
499
500
500
501
Because the cache may rarely have stale data, this should only be
@@ -514,7 +515,7 @@ def get_by_ids(
514
515
result_dict [feature_id ] = feature
515
516
516
517
for future in futures :
517
- unformatted_feature = future .get_result ()
518
+ unformatted_feature : Optional [ Feature ] = future .get_result ()
518
519
if unformatted_feature and not unformatted_feature .deleted :
519
520
feature = unformatted_feature .format_for_template ()
520
521
feature ['updated_display' ] = (
@@ -525,7 +526,7 @@ def get_by_ids(
525
526
result_dict [unformatted_feature .key .integer_id ()] = feature
526
527
527
528
result_list = [
528
- result_dict . get ( feature_id ) for feature_id in feature_ids
529
+ result_dict [ feature_id ] for feature_id in feature_ids
529
530
if feature_id in result_dict ]
530
531
return result_list
531
532
@@ -632,7 +633,7 @@ def getSortingMilestone(feature):
632
633
633
634
@classmethod
634
635
def get_in_milestone (self , milestone : int ,
635
- show_unlisted : bool = False ) -> dict [int , list [dict [str , Any ]]]:
636
+ show_unlisted : bool = False ) -> dict [str , list [dict [str , Any ]]]:
636
637
"""Return {reason: [feaure_dict]} with all the reasons a feature can
637
638
be part of a milestone.
638
639
@@ -648,7 +649,7 @@ def get_in_milestone(self, milestone: int,
648
649
if cached_features_by_type :
649
650
features_by_type = cached_features_by_type
650
651
else :
651
- all_features : dict [int , list [Feature ]] = {}
652
+ all_features : dict [str , list [Feature ]] = {}
652
653
all_features [IMPLEMENTATION_STATUS [ENABLED_BY_DEFAULT ]] = []
653
654
all_features [IMPLEMENTATION_STATUS [DEPRECATED ]] = []
654
655
all_features [IMPLEMENTATION_STATUS [REMOVED ]] = []
@@ -782,10 +783,11 @@ def get_in_milestone(self, milestone: int,
782
783
783
784
def crbug_number (self ) -> Optional [str ]:
784
785
if not self .bug_url :
785
- return
786
+ return None
786
787
m = re .search (r'[\/|?id=]([0-9]+)$' , self .bug_url )
787
788
if m :
788
789
return m .group (1 )
790
+ return None
789
791
790
792
def new_crbug_url (self ) -> str :
791
793
url = 'https://bugs.chromium.org/p/chromium/issues/entry'
@@ -1132,7 +1134,7 @@ def __init__(self, *args, **kwargs):
1132
1134
1133
1135
@classmethod
1134
1136
def get_feature_entry (self , feature_id : int , update_cache : bool = False
1135
- ) -> FeatureEntry :
1137
+ ) -> Optional [ FeatureEntry ] :
1136
1138
KEY = feature_cache_key (FeatureEntry .DEFAULT_CACHE_KEY , feature_id )
1137
1139
feature = rediscache .get (KEY )
1138
1140
@@ -1174,7 +1176,7 @@ def get_by_ids(self, entry_ids: list[int], update_cache: bool=False
1174
1176
procesing a POST to edit data. For editing use case, load the
1175
1177
data from NDB directly.
1176
1178
"""
1177
- result_dict = {}
1179
+ result_dict : dict [ int , int ] = {}
1178
1180
futures = []
1179
1181
1180
1182
for fe_id in entry_ids :
@@ -1192,9 +1194,8 @@ def get_by_ids(self, entry_ids: list[int], update_cache: bool=False
1192
1194
rediscache .set (store_key , entry )
1193
1195
result_dict [entry .key .integer_id ()] = entry
1194
1196
1195
- result_list = [
1196
- result_dict .get (fe_id ) for fe_id in entry_ids
1197
- if fe_id in result_dict ]
1197
+ result_list = [result_dict [fe_id ] for fe_id in entry_ids
1198
+ if fe_id in result_dict ]
1198
1199
return result_list
1199
1200
1200
1201
# Note: get_in_milestone will be in a new file legacy_queries.py.
0 commit comments