Skip to content

Clean up unused or redundant structure/union/interface code paths in tlbparser and codegenerator. - #976

Merged
junkmd merged 12 commits into
enthought:mainfrom
junkmd:remove_redundant_and_dead_code_from_tools
Oct 24, 2026
Merged

junkmd merged 12 commits into
enthought:mainfrom
junkmd:remove_redundant_and_dead_code_from_tools

Conversation

@junkmd

@junkmd junkmd commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

The main goal of this PR is to clean up our code.
I removed old code that was no longer used (dead code) from the parser and code generator. Now, the code returns early when it finds unnecessary steps. This makes the code shorter and simpler.
Specifically, I cleaned up warnings in Parser, extra steps for IUnknown / IDispatch, and unused methods or inheritance code in structures.

This cleanup is safe because Structure and Union are only for data types in COM Automation rules. In COM TYPEKIND:

  • TKIND_RECORD means "a structure with no methods."
  • TKIND_UNION means a union where members share the same memory location.
  • On the other hand, types with methods are defined separately as TKIND_INTERFACE or TKIND_DISPATCH.

So, records and unions only need information about data, such as fields, sizes, and alignments.
They do not need methods, constructors, base classes, or IIDs. Microsoft's COM type descriptions document also says that structures and unions do not have functions.
Now, Structure / Union handle data, and ComInterface / DispInterface handle behaviors. This matches the COM rules.

Impacts

  • The code for parsing and code generation is shorter because unused branches for methods, constructors, base classes, and IIDs were removed.
  • Parser handles IUnknown, IDispatch, and warnings more simply, so it can stop early.
  • The model and code generation for COM records and unions now match the official rules for data types.
  • Valid type libraries do not give methods, constructors, base classes, or IIDs to records or unions. So, there is no change in normal output.
  • Field generation for records and unions and packing by size and alignment still work as before.
  • Code paths for interface methods, IIDs, and base interfaces did not change. There is no impact on ComInterface or DispInterface.

junkmd added 12 commits October 24, 2026 13:44
The parser only passes `Field` objects to records and unions, but
`_Struct_Union_Base` allowed `Field`, `Method`, and `Constructor` members.
Update its member annotation to reflect the objects actually produced by the
parser.
The parser only passes `Field` objects to records and unions, but the
structure generator still handled the unused `Method` and `Constructor`
members. This suggests that this part of `typedesc` came from an older, more
general C or C++ type model. Remove those branches so the model matches the
COM type library rules, and generate structure packing and fields directly.
The parser only passes `Field` objects to records and unions, but the
structure header generator still checked for unused `Method` members. This
suggests that this part of `typedesc` came from an older, more general C or
C++ type model. Remove that obsolete branch so the model matches the COM type
library rules.
The parser only passes `Field` objects to records and unions, but the
structure header generator still emitted helpers based on unused `Method`
members. This suggests that this part of `typedesc` came from an older, more
general C or C++ type model. Remove those obsolete branches so the model
matches the COM type library rules.
Records and unions are data types in the COM type library model. The parser
provides their fields, while the older structure header path also emitted
base classes and an IID. Remove that legacy output so generated structure
headers reflect the data-only model.
Records and unions are data types in the COM type library model. Their
members are fields, and the parser does not provide structure base types.
Remove the code-generator traversal of those obsolete bases so generation
follows the data-only model.
Records and unions are data types in the COM type library model. The parser
only provides their fields, so the obsolete `bases` parameter and stored base
types are unnecessary. Remove them from the type descriptions, parser calls,
packing support, and related packing tests.
@junkmd junkmd added this to the 1.5.0 / Support Python 3.15 milestone Oct 24, 2026
@junkmd junkmd added typing related to Python static typing system coding style Topics related to style, formatters, linters, and delinting. debt labels Oct 24, 2026
@codecov-commenter

codecov-commenter commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.90%. Comparing base (273f5b2) to head (c59788d).

Files with missing lines Patch % Lines
comtypes/tools/codegenerator/codegenerator.py 54.54% 5 Missing ⚠️
comtypes/tools/tlbparser.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #976      +/-   ##
==========================================
+ Coverage   89.61%   89.90%   +0.29%     
==========================================
  Files         143      143              
  Lines       14247    14192      -55     
==========================================
- Hits        12768    12760       -8     
+ Misses       1479     1432      -47     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@junkmd junkmd changed the title Clean up unused structure/union/interface code paths in tlbparser and codegenerator. Clean up unused or redundant structure/union/interface code paths in tlbparser and codegenerator. Oct 24, 2026
@junkmd
junkmd merged commit 800cb2e into enthought:main Oct 24, 2026
222 of 226 checks passed
@junkmd
junkmd deleted the remove_redundant_and_dead_code_from_tools branch October 24, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coding style Topics related to style, formatters, linters, and delinting. debt typing related to Python static typing system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants