22from functools import partial
33
44import msgspec
5+ from msgspec .structs import force_setattr
56
67from betfair_parser .spec .betting .enums import (
78 BetDelayModel ,
@@ -259,7 +260,7 @@ class RunnerMetaData(BaseMessage, frozen=True, rename="upper"):
259260 adjusted_rating : int | None = None # Race-specific ratings that reflect weights allocated in the race
260261 age : int | None = None # The age of the horse
261262 bred : _MetaCountryCode | None = None # The country in which the horse was born
262- cloth_number : int | None = None # The number on the saddle-cloth
263+ cloth_number : int | str | None = None # The number on the saddle-cloth
263264 cloth_number_alpha : str | None = None # The number on the saddle cloth for US paired runners, e.g. "1A"
264265 colour_type : str | None = None # The colour of the horse
265266 colours_description : str | None = None # The textual description of the jockey silk
@@ -291,7 +292,6 @@ class RunnerMetaData(BaseMessage, frozen=True, rename="upper"):
291292 weight_value : float | None = None # The weight of the horse
292293
293294 def __post_init__ (self ):
294- force_setattr = msgspec .structs .force_setattr
295295 cur_year = datetime .now ().year
296296 if self .weight_value is not None and self .weight_value <= 0 :
297297 force_setattr (self , "weight_value" , None )
@@ -303,10 +303,16 @@ def __post_init__(self):
303303 force_setattr (self , "dam_year_born" , None )
304304 if self .damsire_year_born is not None and not cur_year - 60 < self .damsire_year_born < cur_year :
305305 force_setattr (self , "damsire_year_born" , None )
306- if self .cloth_number is not None and not 0 < self .cloth_number < 50 :
307- force_setattr (self , "cloth_number" , None )
308306 if self .age is not None and not 1 < self .age < 30 :
309307 force_setattr (self , "age" , None )
308+ if isinstance (self .cloth_number , str ):
309+ try :
310+ cloth_number = int ("" .join (filter (str .isdigit , self .cloth_number )))
311+ except ValueError :
312+ cloth_number = None
313+ force_setattr (self , "cloth_number" , cloth_number )
314+ if self .cloth_number is not None and not 0 < self .cloth_number < 50 : # type: ignore[operator]
315+ force_setattr (self , "cloth_number" , None )
310316
311317 @property
312318 def colours_url (self ):
0 commit comments