Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
stubgen cli flag to emit `Any` type for untyped function arguments. #4766
This is a feature request for stubgen.
In my use-case, I am executing
class _MyPrivateClass(third_party_util.TheirClass): ...
In this case mypy complains because I'm inheriting from something from a third party library that has no stubs. My first inclination was to simply generate stubs for the third party library, but they aren't annotated and the stubs generated by
# stub_test.py import typing class Foo: def __init__(self, a, b, c): self.a = a self.b = b self.c = c
# stub_test.pyi # Stubs for stub_test (Python 3.6) # # NOTE: This dynamically typed stub was automatically generated by stubgen. from typing import Any class Foo: a: Any = ... b: Any = ... c: Any = ... def __init__(self, a, b, c) -> None: ...
For the purposes of checking against this, it'd be really helpful if stubgen actually made the signature of
I'm not sure if this behavior should be accepted outright, or hidden behind a commandline argument, but it feels like there should be a way to generate stubs where everything is typed (even if the type is
Have you tested your assumption that this makes any difference (e.g. by manually adding some
If you have a concrete (small) example where adding the
Sure, stubs aside, the following code behaves differently depending on which
"""Quick test. This is quick_test.py `mypy --strict quick_test.py` will behave differently depending on which `__init__` you comment out. """ from typing import Any class Foo: def __init__(self, a, b, c) -> None: # def __init__(self, a: Any, b: Any, c: Any) -> None: self.a = a self.b = b self.c = c def do_something() -> None: Foo(10, 12, 13)
I'm not actually sure what flag in mypy is tickling this warning though:
$ mypy --strict --allow-untyped-calls --allow-untyped-defs --allow-incomplete-defs quick_test.py $ mypy --strict --allow-incomplete-defs quick_test.py quick_test.py:10: error: Function is missing a type annotation for one or more arguments $ mypy --strict --allow-untyped-calls quick_test.py quick_test.py:10: error: Function is missing a type annotation for one or more arguments $ mypy --strict --allow-untyped-defs quick_test.py quick_test.py:10: error: Function is missing a type annotation for one or more arguments $ mypy --version mypy 0.570
It's --disallow-incomplete-defs, which is implied by --strict (or --disallow-untyped-defs, if none of the arguments nor the return type are annotated. So I'll concede this is something that stubgen might add. Perhaps you can come up with a PR? It shouldn't be too complicated.
I think it's fine to always do this.…
On Tue, Mar 20, 2018 at 11:06 AM, Matt Gilson ***@***.***> wrote: I might be able to come up with a PR. Do we need to decide on whether to toggle this behind a flag, or do we just add Any all the time? — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#4766 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ACwrMqWnRCwSmvF3H5WcXiIyUNfmT0Iyks5tgUUzgaJpZM4SyWAi> .
-- --Guido van Rossum (python.org/~guido)