Skip to content

Revealed type of click decorators is Any #6156

Closed

Description

@SnoopJ

NOTE: Appears to be caused by #5483. Issue does not occur against stubs prior to 7a9a107 (e.g. with types-click==0.1.12).

The stubs for click annotate the return type of many of the library's decorator factories as IdentityFunction (e.g. see argument stub, but the revealed type when running mypy is Any. See sample program below.

I'm not sure if this is indicative of an underlying bug in mypy or if there's something missing in the usage of IdentityFunction from typeshed that keeps it from resolving that helper. Insight from someone who is more familiar with the details would be appreciated.

Sample program

import click

reveal_type(click.argument("foo"))

@click.command()
@click.argument("foo")
def cli(foo: str) -> None:
    ...

reveal_type(cli)

Output

12:17 [snoopjedi@denton ~]
$ python3 -m mypy --strict repro.py 
repro.py:3: note: Revealed type is "Any"
repro.py:6: error: Untyped decorator makes function "cli" untyped
repro.py:10: note: Revealed type is "click.core.Command"
Found 1 error in 1 file (checked 1 source file)

Version information

  • Python: 3.8.10
  • mypy: 0.910
  • types-click: 7.1.6

NOTE: I am submitting this issue on behalf of a user who asked a question about it in #python on the Libera IRC network.

Activity

  1. JelleZijlstra commented on Oct 12, 2021

    @JelleZijlstra
    Member

    This is probably the same kind of issue as #5751.

  2. Akuli commented on Oct 12, 2021

    @Akuli
    Collaborator

    If you are using the latest click, you don't need types-click, and you should report any issues to click, not to typeshed. See #5423

  3. SnoopJ commented on Oct 12, 2021

    @SnoopJ
    Author

    If you are using the latest click, you don't need types-click, and you should report any issues to click, not to typeshed. See #5423

    Thanks. The issue does not occur for me with click 8.0.3, but this is still a problem for users who are pinned against the older version(s).

    Additional information: I have been told that pyright is able to do the right thing with this stub, which along with #5751 makes me think this issue is already being tracked.

    Closing this issue, thanks for the info y'all.

  4. SamJoan commented on Nov 30, 2021

    @SamJoan

    For what it's worth, I experienced this regression when migrating between development environments due to a pinned dependency which itself pinned click.

    I'm going to completely redo my dependency management in this case because it just makes sense but definitely a regression imo, not sure if it will impact anything else.

  5. hauntsaninja commented on Nov 30, 2021

    @hauntsaninja
    Collaborator

    The only other report we've had of this kind of problem is with types-retry.
    I agree this is problematic and really tough for users to debug, it's something we're now much more aware of / I don't think we really anticipated when we shifted to modular typeshed. There's more discussion in #5751.

  6. SamJoan commented on Dec 7, 2021

    @SamJoan

    Hi @hauntsaninja

    In the end my issue does not seem to be related to this library. I thought it would be but I dug more into it and confirmed it is not. Letting you know so you don't worry about it too much hehe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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