rdkit icon indicating copy to clipboard operation
rdkit copied to clipboard

2023.9.6 duplicate "self" argument in `rdfiltercatalog/__init__.pyi`

Open JHucker opened this issue 1 year ago • 7 comments

Describe the bug Upgrading to 2023.9.6 fails mypy in my pre-commit when importing FilterCatalogParams:

/home/jacobhucker/miniforge3/envs/min_rep_issue/lib/python3.11/site-packages/rdkit-stubs/Chem/rdfiltercatalog/__init__.pyi:671: error: Duplicate argument "self" in function definition
Found 1 error in 1 file (errors prevented further checking)

Viewing this file, self appears untyped and again typed:

class PythonFilterMatcher(FilterMatcherBase):
    __instance_size__: typing.ClassVar[int] = 72
    @staticmethod
    def __reduce__(*args, **kwargs):
        ...
    def __init__(self, self: typing.Any) -> None:
        """
            C++ signature :
                void __init__(_object*,_object*)
        """

To Reproduce Minimal conda environment yaml:

name: min_rep_issue
channels:
  - conda-forge
dependencies:
  - python=3.11.8
  - pip
  - pip:
    - rdkit==2023.9.6
    - mypy==1.10.0

Minimal main.py:

from rdkit.Chem.rdfiltercatalog import FilterCatalogParams

if __name__ == "__main__":
    _ = FilterCatalogParams()

Running mypy:

$ mypy  .
/home/jacobhucker/miniforge3/envs/min_rep_issue/lib/python3.11/site-packages/rdkit-stubs/Chem/rdfiltercatalog/__init__.pyi:671: error: Duplicate argument "self" in function definition
Found 1 error in 1 file (errors prevented further checking)

Expected behavior There should be no errors detected by mypy when scanning the above main.py example.

Configuration (please complete the following information):

  • RDKit version: 2023.9.6
  • OS: Pop!_OS 22.04 LTS
  • Python version (if relevant): 3.11.8
  • Are you using conda? In the minimal example yes, but this firstly originated when installing rdkit via poetry
  • If you are using conda, which channel did you install the rdkit from? as above
  • If you are not using conda: how did you install the RDKit? Via poetry 1.8.2

JHucker avatar Apr 30 '24 01:04 JHucker

Thanks for reporting. Automated stub generation with C++ Python wrappers is tricky. I'll fix that.

ptosco avatar Apr 30 '24 08:04 ptosco

I have a similar issue with rdkit-stubs/Chem/rdMolDescriptors.pyi:185: error: Duplicate argument "self" in function definition

lukasturcani avatar May 02 '24 09:05 lukasturcani

I've been having the same issues, so far pinning to rdkit=2023.09.5 fixes it, which is okay since for now we only need to worry about this error when running mypy

mikemhenry avatar May 06 '24 19:05 mikemhenry

@ptosco Any updates on this? I'm facing the same issue as @lukasturcani

nishant-aionics avatar May 29 '24 23:05 nishant-aionics

FWIW I've changed mypy.ini to the following to keep using rdkit version 2023.9.6:

[mypy]
disallow_untyped_defs = True
; disallow_any_unimported = True
no_implicit_optional = True
check_untyped_defs = True
; warn_return_any = True
show_error_codes = True 
warn_unused_ignores = True
exclude = venv|.venv

[mypy-rdkit.*]
follow_imports = skip
follow_imports_for_stubs = True

nishant-aionics avatar May 29 '24 23:05 nishant-aionics

Apologies, I have had very little time for RDKit lately; I’ll try to get this fixed for the next patch release.

ptosco avatar May 30 '24 08:05 ptosco

Thanks @ptosco! Appreciate the help! 💯

nishant-aionics avatar May 30 '24 15:05 nishant-aionics

The same problem exist in RDKit 2024.3.5 but in the file rdkit-stubs/Chem/rdMolDescriptors.pyi. In this declaration:

    def __init__(self, self: typing.Any, name: str, version: str) -> None:
        """
            C++ signature :
                void __init__(_object*,_object*,std::string,std::string)
        """

there is 2 self where only one should be needed:

    def __init__(self: typing.Any, name: str, version: str) -> None:
        """
            C++ signature :
                void __init__(_object*,_object*,std::string,std::string)
        """

ElricleNecro avatar Sep 05 '24 13:09 ElricleNecro

maybe related to this one: https://github.com/rdkit/rdkit/issues/7554

UnixJunkie avatar Sep 09 '24 04:09 UnixJunkie

Yes, they are both showing the same problem, just in different files. I posted in both, because the incriminated file was mentionned ion both. And I'm not sure which one is really active.

ElricleNecro avatar Sep 09 '24 07:09 ElricleNecro