Skip to content
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

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

Open
sigmaSd opened this issue Nov 8, 2023 · 3 comments
Open
Labels
bug Something isn't working

Comments

@sigmaSd
Copy link
Contributor

sigmaSd commented Nov 8, 2023

import { python } from "https://deno.land/x/[email protected]/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)

@sigmaSd sigmaSd changed the title errors when setting properties on class that extends python class errors when setting properties on a class that extends python class Nov 8, 2023
@sigmaSd
Copy link
Contributor Author

sigmaSd commented Nov 8, 2023

using private variables instead , makes it work

import { python } from "https://deno.land/x/[email protected]/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());

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Nov 9, 2023

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)

@eliassjogreen eliassjogreen added the bug Something isn't working label Nov 11, 2023
@sigmaSd
Copy link
Contributor Author

sigmaSd commented Dec 19, 2023

Here is a more self contained example

import { python } from "https://deno.land/x/[email protected]/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
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants