Skip to content

Inline any(filter(...)) false-positive errors #16277

Open
@Behoston

Description

@Behoston

Bug Report

Looks like mypy loses information about filter parameters only when put directly (inline) into any function with list of objects.

  • It works fine without any function for example using list: list(filter(...)).
  • It works fine with list of primitive types like integers: any(filter(lambda x: x == 1, [1, 2, 3])).
  • Works fine when filter object is saved on variable before applying any.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=2a5a544f2e2ae02f57066ffe5adfa8b7

Expected Behavior

No errors

Actual Behavior

error: Argument 1 to "filter" has incompatible type "Callable[[Any], Any]"; expected "Callable[[Foo], TypeGuard[object]]"  [arg-type]
error: "object" has no attribute "value"  [attr-defined]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.5.1/1.6.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): not allowed to share but nothing special, just some import ignores
  • Python version used: 3.11.0rc1

Activity

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

    bugmypy got something wrongtopic-type-contextType context / bidirectional inference

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Behoston@AlexWaygood

        Issue actions

          Inline any(filter(...)) false-positive errors · Issue #16277 · python/mypy