Skip to content

Allow for type hinting in construct() method #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pythonParsing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as crypto from "crypto";
import { TextDocument, Range } from "vscode";
import { Range, TextDocument } from "vscode";

/**
* Cache is a simple key-value store that keeps a maximum number of entries.
Expand Down Expand Up @@ -206,7 +206,7 @@ export class ManimClass {
/**
* Regular expression to match the construct() method definition.
*/
private static CONSTRUCT_METHOD_REGEX = /^\s*def\s+construct\s*\(self\)\s*:/;
private static CONSTRUCT_METHOD_REGEX = /^\s*def\s+construct\s*\(self\)\s*(->\s*None)?\s*:/;

/**
* The 0-based line number where the Manim Class is defined.
Expand Down
6 changes: 3 additions & 3 deletions tests/cellRanges.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { workspace, Range } from "vscode";
import { describe, it } from "mocha";
import { uriInWorkspace } from "./utils/testRunner";
import { Range, workspace } from "vscode";
import { ManimCellRanges } from "../src/pythonParsing";
import { uriInWorkspace } from "./utils/testRunner";

describe("Manim Cell Ranges", function () {
// in the expected ranges we only care about the start and end lines
// line numbers are 0-based here
const tests = [
{
filename: "detection_basic.py",
expectedRanges: [[5, 7], [9, 10]],
expectedRanges: [[5, 7], [9, 10], [16, 18]],
},
{
filename: "detection_class_definition.py",
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/detection_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ def construct(self):
print("And even more code")


class BasicNotebookWithType(Scene):

def construct(self) -> None:
## Cell inside construct(self) marked with "None" type
print("With some code None")
print("With some more code None")


class NoManimScene(Scene):
def constructtttt(self):
## Should not be detected as Manim Cell
Expand Down