microsoft / microsoft/pxt-microbit

nested namespaces don't work in Python

Open
#3,195 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This typescript:

namespace foo {
    export const baz = 42

    export namespace bar {
        export const baz2 = 84
    }
}

input.onButtonPressed(Button.A, function on_button_pressed_a() {
    basic.showNumber(foo.bar.baz2)
})

converts to this python:

@namespace
class foo:
    baz = 42
    @namespace
    class bar:
        baz2 = 84

def on_button_pressed_a():
    basic.show_number(foo.bar.baz2)
input.on_button_pressed(Button.A, on_button_pressed_a)

with these errors:
image

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 by reproducing the nested namespace example and comparing the generated Python with the reported output and errors. The work is done when the example converts and runs without errors while preserving access to foo.bar.baz2.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.