Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve codegenerator.modulenamer static typing. #590

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions comtypes/tools/codegenerator/modulenamer.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
from typing import Optional

import comtypes
from comtypes import typeinfo


def name_wrapper_module(tlib):
def name_wrapper_module(tlib: typeinfo.ITypeLib) -> str:
"""Determine the name of a typelib wrapper module"""
libattr = tlib.GetLibAttr()
modname = "_%s_%s_%s_%s" % (
str(libattr.guid)[1:-1].replace("-", "_"),
libattr.lcid,
libattr.wMajorVerNum,
libattr.wMinorVerNum,
)
return "comtypes.gen.%s" % modname
guid = str(libattr.guid)[1:-1].replace("-", "_")
modname = f"_{guid}_{libattr.lcid}_{libattr.wMajorVerNum}_{libattr.wMinorVerNum}"
return f"comtypes.gen.{modname}"


def name_friendly_module(tlib):
def name_friendly_module(tlib: typeinfo.ITypeLib) -> Optional[str]:
"""Determine the friendly-name of a typelib module.
If cannot get friendly-name from typelib, returns `None`.
"""
try:
modulename = tlib.GetDocumentation(-1)[0]
except comtypes.COMError:
return
return "comtypes.gen.%s" % modulename
return f"comtypes.gen.{modulename}"