sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
232 stars 47 forks source link

Not sort overload #98

Closed cielavenir closed 1 year ago

cielavenir commented 1 year ago

pybind11 users write overloaded functions order carefully, there are no need to sort them.

/cc @felixvd

sizmailov commented 1 year ago

I don't see the motivation behind this change. What problem you are trying to solve?

cielavenir commented 1 year ago

https://github.com/cielavenir/pybind11_playground/blob/master/src/pybind11_playground.cpp

with this patch:

class toyclass():
    @typing.overload
    def test_overload(self, arg0: str) -> None: ...
    @typing.overload
    def test_overload(self, arg0: object) -> None: ...
    pass

without this patch:

class toyclass():
    @typing.overload
    def test_overload(self, arg0: object) -> None: ...
    @typing.overload
    def test_overload(self, arg0: str) -> None: ...
    pass
$ mypy stubs/pybind11_playground-stubs/pybind11_playground/__init__.pyi 
stubs/pybind11_playground-stubs/pybind11_playground/__init__.pyi:18: error: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader
cielavenir commented 1 year ago

so actually tests/stubs/expected/cpp_library_bindings/_core/opaque_types/__init__.pyi is weird

sizmailov commented 1 year ago

It appears to me that a PEP does not dictate the specific order of overloads, but rather mypy's interpretation of the stubs, which still makes a valid use case.

Originally the sorting of overloads was introduced to circumvent non-deterministic output in python<3.7 (#21). I think there are no drawbacks to merging this PR.

@cielavenir Could you please update the stubs to pass CI?

cielavenir commented 1 year ago

@sizmailov fixed