Skip to content

Infer input type of lambda based on 2nd argument to map() #438

Closed

Description

@bigfootjon

Describe the Bug

It's really easy to write map(lambda foo: ..., ...) but this isn't typechecked

Sandbox Link

https://pyrefly.org/sandbox/?code=MQAgKgFglgziMQPYFcA2ATEBTATjxOAhAFAC2AhgA4AUq5pARuuSAB4BcbAdOoljAH0AdogAuArK1ijqASgA0IANoBGALqzixdFgBmIUQE9K-YWIFQhu3DizpqAN3KpODRIlSyQAWgB8IADlEISx2YhAIkEpyGBgtChojE0ERcUtrPDtFVQ0gA

(Only applicable for extension issues) IDE Information

No response

Activity

  1. yangdanny97 commented on Jun 16, 2025

    @yangdanny97
    Collaborator

    This is a bit tricky, we'll need to use the type of the second argument to map's constructor as part of the contextual type for the first argument. Right now I suspect we're just evaluating arguments left to right.

  2. added theissue type on Jun 16, 2025
  3. changed the title [-]map() does not infer types for lambda expressions[/-] [+]Infer input type of lambda based on 2nd argument to map()[/+] on Jun 16, 2025
  4. samwgoldman commented on Jan 15, 2026

    @samwgoldman
    Member

    Making contextual typing work for calls like this is part of the scope of #105. Going to leave this open because it's a good example, and we could solve #105 without fixing this in theory.

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

Metadata

Metadata

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions