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

Issue with class constructors in python. #8490

Open
FegrusB opened this issue Sep 14, 2021 · 6 comments
Open

Issue with class constructors in python. #8490

FegrusB opened this issue Sep 14, 2021 · 6 comments

Comments

@FegrusB
Copy link

FegrusB commented Sep 14, 2021

I am having an issue when declaring a class in python. I am getting an error 'Type annotation cannot appear on a constructor declaration' I have not used any type annotation. Another user has identified this as an error with converting the python to typescript

class cord:
def init (self, xCord, yCord):
self.x = xCord
self.y = yCord

Type annotation cannot appear on a constructor declaration.

@enauman
Copy link

enauman commented Jun 5, 2022

I'm still encountering this almost a year later. Is this issue still not addressed? Without this fix there is no way to use or teach class construction in Minecraft EE.

@martinwork
Copy link

@enauman @FegrusB This code works in beta

class cord:
    def __init__(self, xCord, yCord):
        self.x = xCord
        self.y = yCord

xy = cord(1,2)

def on_forever():
    basic.show_number(xy.x)
    basic.show_number(xy.y)

basic.forever(on_forever)

@enauman
Copy link

enauman commented Jun 5, 2022

Is there a beta for Minecraft EE? That's where I'm encountering the issue.

@enauman
Copy link

enauman commented Jun 5, 2022

I found the beta (click the gear, click Experimental), though it's not integrated into the game very well. Even so, I get the same error 'Type annotation cannot appear on a constructor declaration'

@Vegz78
Copy link

Vegz78 commented Jun 24, 2022

Experiencing the same also when trying classes in Python on arcade.makecode.com;
'Type annotation cannot appear on a constructor declaration'

Issues:
MAIN:
1. Getting the appended type in constructors for both main class and enumerator class in the "shadow" .ts file which is automatically made parallell to the .py file I am working on.

A little outside this scope, but worth mentioning:
2. The Python enumeration class (class Letter2(Enum):) has to be initialized to be referenced in the other class that uses it, and then a whole lot of strange code is generated in the .ts shadow file:
Py_enumeration_class_ts.txt
I am unable to import and use the enumeration class to make it accessible in one Python file from another "module" file, like was possible for the function below.
UPDATE:
I am wondering it this merge in fact is the reason for the auto generated code for my enumeration class that does not have a constructor?: #8883
UPDATE END
3. While not officially supported, according to this page, I am glad it is still possible to import functions from Python module files, via from customp import functionName, however, there is a strange bug where in Python it is callable without the module file name prefix, while JavaScript makes a namespace with the module name and requires the module prefix namespace.function, forcing either an error in the .py or .ts file. A workaround was to append as anotherName in the import statement in the the .py file, and in a separate .ts file make a similar function reference alias/variable let anotherName = namespace.function, making it callable by anotherName in both main.py and main.ts...

Works a little better on the beta where everything including issue 1 compiles, in the main production webeditor, only 2 and 3. Import to make class accessible from another file in Python, ref. point 2 above, does not work in beta either.

Hope you can have a look at this soon, and nice to see that the Python part is getting closer to the functionality of the JavaScript!

@Vegz78
Copy link

Vegz78 commented Jul 3, 2022

I'm still encountering this almost a year later. Is this issue still not addressed? Without this fix there is no way to use or teach class construction in Minecraft EE.

@enauman: Seems like there has been some recent activity regarding classes in Python lately; #8879

Unsure about how it affects this specific issue, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants