Skip to content

stubgen cli flag to emit Any type for untyped function arguments. #4766

@mgilson-argo

Description

@mgilson-argo

This is a feature request for stubgen.

In my use-case, I am executing mypy --strict --ignore-missing-imports on my package's source files and I use stubgen to generate stubs for my package so that other scripts that import my package can type check against it. I wrote something like:

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 stubgen seem to actively suppress writing Any annotations in function arguments.

e.g.:

# 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 Foo.__init__ to be def __init__(self, a: Any, b: Any, c: Any) -> None .... As implemented currently, I think that this will cause warnings to be generated by mypy --strict for anything that relies on these stubs (I think --disallow-untyped-calls is the culprit) whereas the proposed solution would allow that mypy flag to pass and then I can assert that (at the very least), the code under my control has type annotations for all the functions.

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 Any).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions