@property causes errors due to incorrect generated code
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, python
- Domain
- compilers
Research direction
Reproduce the MWE and inspect the generated props.js output alongside the get implementation shown in the issue. Trace the generated Foo property definitions and property access, then verify that both properties reference the correct implementation functions and return values rather than attempting to call them.
Written by the indexing model from the issue text.
Description
MWE:
class Foo:
@property
def bar(self):
return 'Hello World'
@property
def name(self):
return 'John Smith'
foo = Foo()
print(foo.bar) # Should print "Hello World"
print(foo.name) # Should print "John Smith"
The relevant Transcrypt output is:
var Foo = __class__ ('Foo', 'props', [object], {
__impl__bar: function (self) {
return 'Hello World';
},
get bar () {return __get__ (this, this.__impl__bar);},
__impl__name: function (self) {
return 'John Smith';
},
get py_name () {return __get__ (this, this.__impl__name);}
})
Object.defineProperty (Foo, '__impl__bar', property.call (Foo, Foo.Foo.__impl__bar));;
Object.defineProperty (Foo, '__impl__name', property.call (Foo, Foo.Foo.__implpy_name));;;
Note that __impl__bar is defined as Foo.__impl__bar, but is referenced in the defineProperty call as Foo.Foo.__impl__bar. This causes an error, as Foo.Foo is undefined:
.../props.js:2450
Object.defineProperty (Foo, '__impl__bar', property.call (Foo, Foo.Foo.__impl__bar));;
^
TypeError: Cannot read property '__impl__bar' of undefined
A simple workaround is to patch the output: perl -0777 -pi -e 's/property.call \((.*?), \g1.\g1.__impl__(.*?)\)/property.call ($1, $1.__impl__$2)/g' path/to/file.js
Note that for Foo.name, there is a slightly different problem as well, in that the function is defined as __impl__name, but is referenced as __implpy_name, causing a further error.
Again, a simple workaround suffices for now: perl -0777 -pi -e 's/property.call \((.*?), \g1.\g1.__implpy_(.*?)\)/property.call ($1, $1.__impl__$2)/g' path/to/file.js
Even after applying these patches however, @property is still not functional because e.g. foo.bar ends up being wrapped as a function that attempts to "call" foo.bar. This, of course, fails, because foo.bar is not a function.
The issue appears to be in the implementation __get__:
var __get__ = function (self, func, quotedFuncName) {
if (self) {
if (self.hasOwnProperty ('__class__') || typeof self == 'string' || self instanceof String) { // Object before the dot
if (quotedFuncName) { // Memoize call since fcall is on, by installing bound function in instance
// ...
// The property is defined as a function instead of a value
Inserting a statement if(typeof(func) != "function"){return func;} at the very beginning of this function seems to fix the issue.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 218
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TranscryptOrg/Transcrypt
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
TranscryptOrg/Transcrypt#913 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
TranscryptOrg/Transcrypt#911 · 2 comments ·
-
IS: bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
TranscryptOrg/Transcrypt#908 ·
-
SUB: documentation
Difficulty 1/5 Under an hour Newbie friendliness 62/100
TranscryptOrg/Transcrypt#656 · 7 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
TranscryptOrg/Transcrypt#914 ·
All issues in TranscryptOrg/Transcrypt
Similar issues
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NousResearch/hermes-agent#117848 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100