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

@typing.overload-ed methods not supported #208

Closed
EFord36 opened this issue Nov 15, 2023 · 1 comment · Fixed by #209
Closed

@typing.overload-ed methods not supported #208

EFord36 opened this issue Nov 15, 2023 · 1 comment · Fixed by #209

Comments

@EFord36
Copy link
Contributor

EFord36 commented Nov 15, 2023

Following on from #196 - sorry, I probably should have highlighted methods as important to me.

When docsig checks the following code:

class SomeClass:

    @overload
    def process(self, response: None) -> None:
        ...
    @overload
    def process(self, response: int) -> tuple[int, str]:
        ...
    @overload
    def process(self, response: bytes) -> str:
        ...
    def process(self, response):
        """process a response.

        :param response: the response to process
        :return: something depending on what the response is
        """
        ...  # actual implementation goes here

I get the following error:

no_vc/test_docsig_methods.py:12 in SomeClass
--------------------------------------------
def process(✖None) -> ✓str:
    """
    :param response: ✖
    :return: ✓
    """

E102: includes parameters that do not exist

I had a go debugging and think I've tracked down the issue:

inserting:

                        if func.name == "process":
                            breakpoint()

just before this line

and then running subnode.args.arguments shows that the self argument isn't prevent, as it appears to be for a non-overload-ed method:

debugging session:

> docsig/_module.py(61)__init__()
-> func = _Function(
(Pdb) subnode.args.arguments
[<AssignName.response l.12 at 0x1058eeb80>]
(Pdb) 

Then, when creating the _Signature, docsig pops the first argument if the relevant function is a (non-static) method, which in this case is the 'actual' first argument response.

@EFord36
Copy link
Contributor Author

EFord36 commented Nov 15, 2023

Just dug into a bit more why it is the case that the 'self' is missing - should have been obvious to me the first time, sorry!

It's because we end up creating a function twice and therefore the pop gets done twice.

EFord36 added a commit to EFord36/docsig that referenced this issue Nov 15, 2023
EFord36 added a commit to EFord36/docsig that referenced this issue Nov 16, 2023
Signed-off-by: Elliot Ford <elliot.ford@hotmail.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant