Skip to content

Commit c59f352

Browse files
author
Roman
committed
Ensure null checks use "is not None" consistently
1 parent 66e8688 commit c59f352

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

bittensor/core/chain_data/metagraph_info.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
157157
decoded.update({"symbol": bytes(symbol).decode()})
158158

159159
ii_list = []
160-
if decoded.get("identity"):
160+
if decoded.get("identity") is not None:
161161
ii_list.append("identity")
162162

163-
if decoded.get("identities"):
163+
if decoded.get("identities") is not None:
164164
ii_list.append("identities")
165165

166166
for key in ii_list:
@@ -178,10 +178,10 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
178178
network_registered_at=decoded["network_registered_at"],
179179
# Keys for owner.
180180
owner_hotkey=decode_account_id(decoded["owner_hotkey"][0])
181-
if decoded.get("owner_hotkey")
181+
if decoded.get("owner_hotkey") is not None
182182
else None,
183183
owner_coldkey=decode_account_id(decoded["owner_coldkey"][0])
184-
if decoded.get("owner_coldkey")
184+
if decoded.get("owner_coldkey") is not None
185185
else None,
186186
# Tempo terms.
187187
block=decoded["block"],
@@ -202,17 +202,17 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
202202
moving_price=Balance.from_tao(
203203
fixed_to_float(decoded.get("moving_price"), 32)
204204
)
205-
if decoded.get("moving_price")
205+
if decoded.get("moving_price") is not None
206206
else None,
207207
# Hparams for epoch
208208
rho=decoded["rho"],
209209
kappa=decoded["kappa"],
210210
# Validator params
211211
min_allowed_weights=u16tf(decoded["min_allowed_weights"])
212-
if decoded["min_allowed_weights"]
212+
if decoded.get("min_allowed_weights") is not None
213213
else None,
214214
max_weights_limit=u16tf(decoded["max_weights_limit"])
215-
if decoded["max_weights_limit"]
215+
if decoded["max_weights_limit"] is not None
216216
else None,
217217
weights_version=decoded["weights_version"],
218218
weights_rate_limit=decoded["weights_rate_limit"],
@@ -222,20 +222,22 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
222222
num_uids=decoded["num_uids"],
223223
max_uids=decoded["max_uids"],
224224
burn=_tbwu(decoded["burn"]),
225-
difficulty=u64tf(decoded["difficulty"]) if decoded["difficulty"] else None,
225+
difficulty=u64tf(decoded["difficulty"])
226+
if decoded["difficulty"] is not None
227+
else None,
226228
registration_allowed=decoded["registration_allowed"],
227229
pow_registration_allowed=decoded["pow_registration_allowed"],
228230
immunity_period=decoded["immunity_period"],
229231
min_difficulty=u64tf(decoded["min_difficulty"])
230-
if decoded["min_difficulty"]
232+
if decoded["min_difficulty"] is not None
231233
else None,
232234
max_difficulty=u64tf(decoded["max_difficulty"])
233-
if decoded["max_difficulty"]
235+
if decoded["max_difficulty"] is not None
234236
else None,
235237
min_burn=_tbwu(decoded["min_burn"]),
236238
max_burn=_tbwu(decoded["max_burn"]),
237239
adjustment_alpha=u64tf(decoded["adjustment_alpha"])
238-
if decoded["adjustment_alpha"]
240+
if decoded["adjustment_alpha"] is not None
239241
else None,
240242
adjustment_interval=decoded["adjustment_interval"],
241243
target_regs_per_interval=decoded["target_regs_per_interval"],
@@ -246,69 +248,73 @@ def _from_dict(cls, decoded: dict) -> "MetagraphInfo":
246248
commit_reveal_period=decoded["commit_reveal_period"],
247249
# Bonds
248250
liquid_alpha_enabled=decoded["liquid_alpha_enabled"],
249-
alpha_high=u16tf(decoded["alpha_high"]) if decoded["alpha_high"] else None,
250-
alpha_low=u16tf(decoded["alpha_low"]) if decoded["alpha_low"] else None,
251+
alpha_high=u16tf(decoded["alpha_high"])
252+
if decoded["alpha_high"] is not None
253+
else None,
254+
alpha_low=u16tf(decoded["alpha_low"])
255+
if decoded["alpha_low"] is not None
256+
else None,
251257
bonds_moving_avg=u64tf(decoded["bonds_moving_avg"])
252-
if decoded["bonds_moving_avg"]
258+
if decoded["bonds_moving_avg"] is not None
253259
else None,
254260
# Metagraph info.
255261
hotkeys=[decode_account_id(ck) for ck in decoded.get("hotkeys", [])]
256-
if decoded.get("hotkeys")
262+
if decoded.get("hotkeys") is not None
257263
else None,
258264
coldkeys=[decode_account_id(hk) for hk in decoded.get("coldkeys", [])]
259-
if decoded.get("coldkeys")
265+
if decoded.get("coldkeys") is not None
260266
else None,
261267
identities=decoded["identities"],
262268
axons=decoded.get("axons", []),
263269
active=decoded["active"],
264270
validator_permit=decoded["validator_permit"],
265271
pruning_score=[u16tf(ps) for ps in decoded.get("pruning_score", [])]
266-
if decoded.get("pruning_score")
272+
if decoded.get("pruning_score") is not None
267273
else None,
268274
last_update=decoded["last_update"],
269275
emission=[_tbwu(em, _netuid) for em in decoded.get("emission", [])]
270-
if decoded.get("emission")
276+
if decoded.get("emission") is not None
271277
else None,
272278
dividends=[u16tf(dv) for dv in decoded.get("dividends", [])]
273-
if decoded.get("dividends")
279+
if decoded.get("dividends") is not None
274280
else None,
275281
incentives=[u16tf(ic) for ic in decoded.get("incentives", [])]
276-
if decoded.get("incentives")
282+
if decoded.get("incentives") is not None
277283
else None,
278284
consensus=[u16tf(cs) for cs in decoded.get("consensus", [])]
279-
if decoded.get("consensus")
285+
if decoded.get("consensus") is not None
280286
else None,
281287
trust=[u16tf(tr) for tr in decoded.get("trust", [])]
282-
if decoded.get("trust")
288+
if decoded.get("trust") is not None
283289
else None,
284290
rank=[u16tf(rk) for rk in decoded.get("rank", [])]
285-
if decoded.get("rank")
291+
if decoded.get("rank") is not None
286292
else None,
287293
block_at_registration=decoded["block_at_registration"],
288294
alpha_stake=[_tbwu(ast, _netuid) for ast in decoded["alpha_stake"]]
289-
if decoded.get("alpha_stake")
295+
if decoded.get("alpha_stake") is not None
290296
else None,
291297
tao_stake=[
292298
_tbwu(ts) * settings.ROOT_TAO_STAKE_WEIGHT
293299
for ts in decoded["tao_stake"]
294300
]
295-
if decoded.get("tao_stake")
301+
if decoded.get("tao_stake") is not None
296302
else None,
297303
total_stake=[_tbwu(ts, _netuid) for ts in decoded["total_stake"]]
298-
if decoded.get("total_stake")
304+
if decoded.get("total_stake") is not None
299305
else None,
300306
# Dividend break down
301307
tao_dividends_per_hotkey=[
302308
(decode_account_id(alpha[0]), _tbwu(alpha[1]))
303309
for alpha in decoded["tao_dividends_per_hotkey"]
304310
]
305-
if decoded.get("tao_dividends_per_hotkey")
311+
if decoded.get("tao_dividends_per_hotkey") is not None
306312
else None,
307313
alpha_dividends_per_hotkey=[
308314
(decode_account_id(adphk[0]), _tbwu(adphk[1], _netuid))
309315
for adphk in decoded["alpha_dividends_per_hotkey"]
310316
]
311-
if decoded.get("alpha_dividends_per_hotkey")
317+
if decoded.get("alpha_dividends_per_hotkey") is not None
312318
else None,
313319
)
314320

0 commit comments

Comments
 (0)