microsoft / microsoft/pxt-microbit

Python editor gives error with lambdas

Open
#3,380 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P2 python
Dominant language
TypeScript
Stars
804
Forks
721
Avg merge
2d 9h
Merged PRs (30d)
2

Description

Describe the bug
Lambda variables are treated as non-callable. Upon creating a lambda, trying to call it I receive an error stating that I'm trying to "Call a non-function".

To Reproduce

f = lambda x: x*x
basic.show_number(f(2))

Error: Line 2: calling non-function

This happens even when annotating f with : function

Expected behavior
Lambdas working

Desktop:

  • OS: Linux
  • Browser: Mozilla Firefox 80.0.1

Additional context
Error appears both on master branch, and live version.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the Python editor by reproducing the reported lambda snippet and tracing how the editor determines whether a variable is callable. Verify both the unannotated and function-annotated forms, and consider the work complete when calling the lambda no longer reports “calling non-function” and the example displays 4.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
devtools, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.