Skip to content

Conversation

eugeneliukindev
Copy link

@eugeneliukindev
Copy link
Author

@srittau
During the changes I encountered the following problem:

Source code:

class NumWorkersChanged(Setting):
    def nworkers_changed(server, new_value, old_value):
        pass

    default = staticmethod(nworkers_changed)

The nworkers_changed method is used only as a pass through to the staticmethod function to set the default value.

When trying to write stubs:

def nworkers_changed(server: Arbiter, new_value: int, old_value: int | None) -> None: ... 

I get the following error from mypy:

gunicorn/config.pyi:846: error: Self argument missing for a non-static method (or an invalid type for self)  [misc]
        def nworkers_changed(server: Arbiter, new_value: int, old_value: int | None) -> None: ...
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

How can I properly create a stub so I don't have to write type: ignore[misc]? If I add the @staticmethod decorator, it won't match the original function signature, and stubtest will also complain.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/worker.py:38: error: Unused "type: ignore[misc, no-any-unimported]" comment  [unused-ignore]
+ aiohttp/worker.py:71:13: error: Statement is unreachable  [unreachable]
+ aiohttp/worker.py:71:13: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-unreachable for more info
+ aiohttp/worker.py:75:26: error: Too few arguments  [call-arg]
+ aiohttp/worker.py:75:26: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-call-arg for more info
+ aiohttp/worker.py:75:26: note: "wsgi" is considered instance variable, to make it class variable use ClassVar[...]
+ aiohttp/worker.py:117: error: Unused "type: ignore" comment  [unused-ignore]

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 this pull request may close these issues.

3 participants