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

overloads without implementations (in stub files) are not detected #116

Closed
tlambert03 opened this issue Nov 19, 2022 · 6 comments
Closed
Labels
bug Something isn't working griffe: wildcard-imports Related to wildcard imports

Comments

@tlambert03
Copy link
Contributor

tlambert03 commented Nov 19, 2022

Describe the bug
Methods and functions that are decorated with @overload but do not have an implementation (as is standard in a stub file) are not detected:

To Reproduce

# mystub.pyi
from typing import overload

class M:
    @overload
    def f(self, x: int) -> int: ...
    @overload
    def f(self, x: str) -> str: ...

class M2:
    @overload
    def f(self, x: int) -> int: ...
    @overload
    def f(self, x: str) -> str: ...
    def f(self, x: str | int) -> str | int: ...  # one wouldn't normally do this in a stub
In [3]: griffe.load('mystub._test.M').members
Out[3]: {}

In [4]: griffe.load('mystub._test.M2').members
Out[4]: {'f': <Function('f', 14, 14)>}

Expected behavior
Expected f method to be detected.

System (please complete the following information):

  • griffe version: 0.24.1
  • Python version: 3.10
  • OS: mac

Will probably be relevant for mkdocstrings/mkdocstrings#308 as well

@pawamoy
Copy link
Member

pawamoy commented Nov 19, 2022

Thanks for the report!
It may be a bug in the code that merges stubs data into actual module data, but I can't see it 🤔
Do you have a public repo I could use to debug?

@tlambert03
Copy link
Contributor Author

tlambert03 commented Nov 19, 2022

the repo i found it on was that same (compiled) pymmcore repo. so

pip install pymmcore
def test_overloads():
    import griffe
    core = griffe.load('pymmcore.CMMCore')
    
    # defineConfig is overloaded
    assert 'defineConfig' in core.members

    # this is a non-overloaded function that works already
    assert 'addSearchPath' in core.members

and the corresponding stub is at https://github.com/micro-manager/pymmcore/blob/main/pymmcore/__init__.pyi

@pawamoy
Copy link
Member

pawamoy commented Nov 25, 2022

Ah, found the issue. It's because we merge stubs before wildcard imports were expanded.

@pawamoy pawamoy added griffe: wildcard-imports Related to wildcard imports bug Something isn't working labels Nov 25, 2022
@pawamoy
Copy link
Member

pawamoy commented Nov 25, 2022

Another issue is that ./pymmcore is found first, rather than the installed version which is the only one containing the compiled module _pymmcore_swig.cpython-311-x86_64-linux-gnu. So the compiled module is not found, not inspected, and we can't expand wildcards, and merge stubs.

An argument in favor of the src-layout I guess. I'll try with it, to see if it's better.

@pawamoy
Copy link
Member

pawamoy commented Nov 25, 2022

OK, we need #115 first.

@pawamoy
Copy link
Member

pawamoy commented Nov 30, 2022

Fixed in 0ed9c36

@pawamoy pawamoy closed this as completed Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working griffe: wildcard-imports Related to wildcard imports
Projects
None yet
Development

No branches or pull requests

2 participants