Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
- Examples for str, list
- Don't import "builtins" or fully qualify it
  • Loading branch information
microbit-matt-hillsdon committed May 24, 2024
1 parent ee27118 commit 9ee4699
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 25 deletions.
15 changes: 11 additions & 4 deletions src/documentation/api/ApiNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,28 @@ const classToInstanceMap: Record<string, string> = {
MicroBitAnalogDigitalPin: "pin0",
Image: "Image.HEART",
uname_result: "uname()",
str: `"hello, world"`,
list: `[1, 2, 3]`,
};

const getDragPasteData = (fullName: string, kind: string): PasteContext => {
let parts = fullName.split(".").filter((p) => p !== "__init__");
let parts = fullName
.split(".")
.filter((p) => p !== "__init__" && p !== "__new__");
// Heuristic identification of e.g. Image.HEART. Sufficient for MicroPython API.
if (!parts[parts.length - 1].match(/^[A-Z0-9_]+$/)) {
parts = parts.map((p) => classToInstanceMap[p] ?? p);
}
const isMicrobit = parts[0] === "microbit";
const nameAsWeImportIt = isMicrobit ? parts.slice(1) : parts;
const isBuiltin = parts[0] === "builtins";
const nameAsWeImportIt = isMicrobit || isBuiltin ? parts.slice(1) : parts;
const code = nameAsWeImportIt.join(".") + (kind === "function" ? "()" : "");
const requiredImport = isMicrobit
const requiredImport = isBuiltin
? undefined
: isMicrobit
? `from microbit import *`
: `import ${parts[0]}`;
const full = `${requiredImport}\n${code}`;
const full = [requiredImport, code].filter((x) => !!x).join("\n");
return {
code,
codeWithImports: full,
Expand Down
4 changes: 2 additions & 2 deletions src/micropython/main/typeshed.ca.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/micropython/main/typeshed.de.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/micropython/main/typeshed.en.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/micropython/main/typeshed.es-es.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/micropython/main/typeshed.fr.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/micropython/main/typeshed.ja.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/micropython/main/typeshed.ko.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/micropython/main/typeshed.nl.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/micropython/main/typeshed.zh-cn.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/micropython/main/typeshed.zh-tw.json

Large diffs are not rendered by default.

0 comments on commit 9ee4699

Please sign in to comment.