3636from pathlib import Path
3737import re
3838from textwrap import dedent , indent as tw_indent
39- import typing
39+ from typing import Optional , cast , List , Union , Iterator
4040
4141import inflection # type: ignore
4242
@@ -206,11 +206,11 @@ def from_json(cls, type):
206206class CdpProperty :
207207 ''' A property belonging to a non-primitive CDP type. '''
208208 name : str
209- description : typing . Optional [str ]
210- type : typing . Optional [str ]
211- ref : typing . Optional [str ]
212- enum : typing . List [str ]
213- items : typing . Optional [CdpItems ]
209+ description : Optional [str ]
210+ type : Optional [str ]
211+ ref : Optional [str ]
212+ enum : List [str ]
213+ items : Optional [CdpItems ]
214214 optional : bool
215215 experimental : bool
216216 deprecated : bool
@@ -236,7 +236,7 @@ def py_annotation(self):
236236 ann = py_ref
237237 else :
238238 ann = CdpPrimitiveType .get_annotation (
239- typing . cast (str , self .type ))
239+ cast (str , self .type ))
240240 if self .optional :
241241 ann = f'typing.Optional[{ ann } ]'
242242 return ann
@@ -316,11 +316,11 @@ def generate_from_json(self, dict_):
316316class CdpType :
317317 ''' A top-level CDP type. '''
318318 id : str
319- description : typing . Optional [str ]
319+ description : Optional [str ]
320320 type : str
321- items : typing . Optional [CdpItems ]
322- enum : typing . List [str ]
323- properties : typing . List [CdpProperty ]
321+ items : Optional [CdpItems ]
322+ enum : List [str ]
323+ properties : List [CdpProperty ]
324324
325325 @classmethod
326326 def from_json (cls , type_ ):
@@ -500,7 +500,7 @@ def generate_code(self):
500500 py_type = f"{ ref_to_python (self .ref )} "
501501 else :
502502 py_type = CdpPrimitiveType .get_annotation (
503- typing . cast (str , self .type ))
503+ cast (str , self .type ))
504504 if self .optional :
505505 py_type = f'typing.Optional[{ py_type } ]'
506506 code = f"{ self .py_name } : { py_type } "
@@ -585,8 +585,8 @@ class CdpCommand:
585585 description : str
586586 experimental : bool
587587 deprecated : bool
588- parameters : typing . List [CdpParameter ]
589- returns : typing . List [CdpReturn ]
588+ parameters : List [CdpParameter ]
589+ returns : List [CdpReturn ]
590590 domain : str
591591
592592 @property
@@ -605,8 +605,8 @@ def from_json(cls, command, domain) -> 'CdpCommand':
605605 command .get ('description' ),
606606 command .get ('experimental' , False ),
607607 command .get ('deprecated' , False ),
608- [typing . cast (CdpParameter , CdpParameter .from_json (p )) for p in parameters ],
609- [typing . cast (CdpReturn , CdpReturn .from_json (r )) for r in returns ],
608+ [cast (CdpParameter , CdpParameter .from_json (p )) for p in parameters ],
609+ [cast (CdpReturn , CdpReturn .from_json (r )) for r in returns ],
610610 domain ,
611611 )
612612
@@ -712,10 +712,10 @@ def get_refs(self):
712712class CdpEvent :
713713 ''' A CDP event object. '''
714714 name : str
715- description : typing . Optional [str ]
715+ description : Optional [str ]
716716 deprecated : bool
717717 experimental : bool
718- parameters : typing . List [CdpParameter ]
718+ parameters : List [CdpParameter ]
719719 domain : str
720720
721721 @property
@@ -731,7 +731,7 @@ def from_json(cls, json: dict, domain: str):
731731 json .get ('description' ),
732732 json .get ('deprecated' , False ),
733733 json .get ('experimental' , False ),
734- [typing . cast (CdpParameter , CdpParameter .from_json (p ))
734+ [cast (CdpParameter , CdpParameter .from_json (p ))
735735 for p in json .get ('parameters' , [])],
736736 domain
737737 )
@@ -786,12 +786,12 @@ def get_refs(self):
786786class CdpDomain :
787787 ''' A CDP domain contains metadata, types, commands, and events. '''
788788 domain : str
789- description : typing . Optional [str ]
789+ description : Optional [str ]
790790 experimental : bool
791- dependencies : typing . List [str ]
792- types : typing . List [CdpType ]
793- commands : typing . List [CdpCommand ]
794- events : typing . List [CdpEvent ]
791+ dependencies : List [str ]
792+ types : List [CdpType ]
793+ commands : List [CdpCommand ]
794+ events : List [CdpEvent ]
795795
796796 @property
797797 def module (self ):
@@ -826,8 +826,8 @@ def generate_code(self):
826826 code += import_code
827827 code += '\n \n '
828828 code += '\n '
829- item_iter_t = typing . Union [CdpEvent , CdpCommand , CdpType ]
830- item_iter : typing . Iterator [item_iter_t ] = itertools .chain (
829+ item_iter_t = Union [CdpEvent , CdpCommand , CdpType ]
830+ item_iter : Iterator [item_iter_t ] = itertools .chain (
831831 iter (self .types ),
832832 iter (self .commands ),
833833 iter (self .events ),
0 commit comments