InChI module typehints · rdkit/rdkit · Discussion #8749 (original) (raw)

Not sure if the rdkit-stubs generation is open to PRs. In my builds I've added the following modification to inchi.pyi generation:

        if filepath.name == "inchi.pyi":
            with open(filepath, "r", encoding="utf-8") as f:
                content = f.read()
            # Modify the content as needed
            lines = [
                ("def InchiToInchiKey(inchi):", "def InchiToInchiKey(inchi: str) -> typing.Optional[str]:"),
                ("def MolBlockToInchi(molblock, options = '', logLevel = None, treatWarningAsError = False):", "def MolBlockToInchi(molblock: str, options: str = '', logLevel: typing.Optional[int] = None, treatWarningAsError: bool = False) -> str:"),
                ("def MolBlockToInchiAndAuxInfo(molblock, options = '', logLevel = None, treatWarningAsError = False):", "def MolBlockToInchiAndAuxInfo(molblock: str, options: str = '', logLevel: typing.Optional[int] = None, treatWarningAsError: bool = False) -> typing.Tuple[str, str]:"),
                ("def MolToInchi(mol, options = '', logLevel = None, treatWarningAsError = False):", "def MolToInchi(mol: Chem.Mol, options: str = '', logLevel: typing.Optional[int] = None, treatWarningAsError: bool = False) -> str:"),
                ("def MolToInchiAndAuxInfo(mol, options = '', logLevel = None, treatWarningAsError = False):", "def MolToInchiAndAuxInfo(mol: Chem.Mol, options: str = '', logLevel: typing.Optional[int] = None, treatWarningAsError: bool = False) -> typing.Tuple[str, str]:"),
                ("def MolToInchiKey(mol, options = ''):", "def MolToInchiKey(mol: Chem.Mol, options: str = '') -> str:"),
            ]
            for old, new in lines:
                content = content.replace(old, new)
            with open(filepath, "w", encoding="utf-8") as f:
                f.write(content)

@ptosco Does it makes sense to do something like this upstream in this repo? Directly in the inchi.py file? In the worker.py generator? Some other place?