Skip to content

errors when setting properties on a class that extends python class #54

Description

@sigmaSd
import { python } from "https://deno.land/x/python@0.4.1/mod.ts";

const gi = python.import("gi");
gi.require_version("Gtk", "4.0");
const Gtk = python.import("gi.repository.Gtk");

class MainWindow extends Gtk.ApplicationWindow {
  constructor() {
    super();
    this.a = 4; // error here
  }
}
console.log(new MainWindow());
error: Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'a'
    this.a = 4;
          ^
    at new MainWindow (file:///home/mrcool/dev/deno/lab/b.ts:10:11)
    at file:///home/mrcool/dev/deno/lab/b.ts:14:13

more info here #53 (comment)

Activity

  1. changed the title [-]errors when setting properties on class that extends python class[/-] [+]errors when setting properties on a class that extends python class[/+] on Nov 8, 2023
  2. sigmaSd commented on Nov 8, 2023

    @sigmaSd
    ContributorAuthor

    using private variables instead , makes it work

    import { python } from "https://deno.land/x/python@0.4.1/mod.ts";
    
    const gi = python.import("gi");
    gi.require_version("Gtk", "4.0");
    const Gtk = python.import("gi.repository.Gtk");
    
    class MainWindow extends Gtk.ApplicationWindow {
     #a;
      constructor() {
        super();
        this.#a = 4; // no error
      }
    }
    console.log(new MainWindow());
  3. sigmaSd commented on Nov 9, 2023

    @sigmaSd
    ContributorAuthor

    I'm "porting" https://github.com/Taiko2k/GTK4PythonTutorial to deno-python and taking note of issues I find along the way here https://github.com/sigmaSd/deno-gtk-py (grep FIXME)

  4. sigmaSd commented on Dec 19, 2023

    @sigmaSd
    ContributorAuthor

    Here is a more self contained example

    import { python } from "https://deno.land/x/python@0.4.2/mod.ts";
    
    const m = python.runModule(
      `
    class A:
      x = 4
      `,
    );
    
    class B extends m.A {
      b;
      constructor() {
        super();
        this.b = 5; // error origin
      }
    }
    
    const _b = new B(); // error here

    This is annoying in practice because it means I can't access any properties/functions of a class from the outside.

    I wonder if there is a way to expose an alternative api for the proxy that allows such things.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions