comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

carve out `CodeGenerator.type_name` method to `TypeNamer` class

Open junkmd opened this issue 3 years ago • 2 comments

As a result of previous refactoring, CodeGenerator.type_name no longer references self except recursively using self.type_name.

Therefore, it is now possible to carve out a process into a separate class without having to consider side-effects or callbacks.

Only one concrete class TypeNamer is defined in this change. For use in creating stubs, these may in the future be a base abstract class and multiple derived classes.

junkmd avatar Sep 20 '22 00:09 junkmd

@vasily-v-ryabov

I made TypeNamer callable itself.

junkmd avatar Sep 22 '22 11:09 junkmd

@vasily-v-ryabov

If this PR is merged, the next step is to create derived classes for generating runtime code and for generating type hint stub.

The first would be to make the External conditional branch an abstract method.

  • For runtime code generation, the symbol of wrapper-module (e.g. _xxxxxxxxxx_xxxxxx_xxxxxx_xxxxxx_xxxxxxxxxxxxxxxxxx.ExternalSymbol) will be returned.
  • For type hint stub generation, the symbol of friendly-named-module (e.g. friendly.ExternalSymbol) will be returned.

junkmd avatar Oct 02 '22 13:10 junkmd

@vasily-v-ryabov

Welcome back!

Passing the instance-bound method is indeed complicated, so I think your suggestion was an appropriate one.

junkmd avatar Nov 01 '22 15:11 junkmd