In tlbparser, if the pBstrDocString parameter of GetDocumentation was not null, the doc attribute was being patched to CoClass, ComInterface, DispInterface, and Constant. Such patching is a typical example of legacy code that triggers warnings from static type checkers, and was the reason why hasattr had to be used in codegenerator.
By taking doc: str | None as a constructor argument and assigning it to an attribute, and changing if hasattr(obj, 'doc', None): to if obj.doc:, this improves the type safety of the codebase.
DispInterface and ComInterface were taking an empty list as a constructor argument and assigning it to the members attribute. Then, they were directly accessing the members.append method to add elements.
By instantiating a list in __init__ and assigning it to members and adding elements through add_member/extend_members, this simplifies the codebase.
tlbparser
, if thepBstrDocString
parameter ofGetDocumentation
was not null, thedoc
attribute was being patched toCoClass
,ComInterface
,DispInterface
, andConstant
. Such patching is a typical example of legacy code that triggers warnings from static type checkers, and was the reason whyhasattr
had to be used incodegenerator
. By takingdoc: str | None
as a constructor argument and assigning it to an attribute, and changingif hasattr(obj, 'doc', None):
toif obj.doc:
, this improves the type safety of the codebase.DispInterface
andComInterface
were taking an empty list as a constructor argument and assigning it to themembers
attribute. Then, they were directly accessing themembers.append
method to add elements. By instantiating a list in__init__
and assigning it tomembers
and adding elements throughadd_member
/extend_members
, this simplifies the codebase.