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

[Bug] If program have input number with "0" start, import seems will no downlaod to brick. #1981

Open
a10036gt opened this issue Dec 19, 2024 · 4 comments
Labels
bug Something isn't working software: pybricks-code Issues with https://code.pybricks.com application

Comments

@a10036gt
Copy link

Describe the bug
If program have input number with "0" start (e.g. print(50) -> print(050)), import seems will no downlaod to brick. Some time just wrongly type extra 0 in front of the original input number, but if there is no import, program still work.

To reproduce
Steps to reproduce the behavior:

  1. Create a Main program
  2. Create a Lib program for import (from IssueTest_Lib import test, import IssueTest_Lib as lib, from IssueTest_Lib import *)
  3. In Main Porgram import Lib, and do some simple staff like wait and print
  4. Change number input from nn to 0nn.

Expected behavior
If no import, seems program works fine even number input is "0nn"

Screenshots

Pybricks.Code.-.Google.Chrome.2024-12-19.18-44-58.2.mp4
@a10036gt a10036gt added the triage Issues that have not been triaged yet label Dec 19, 2024
@BertLindeman
Copy link

BertLindeman commented Dec 19, 2024

Thank you for reporting.

In this case there is a circumvention to not use the leading zero.
But it is a strange way to react like this.

Confirmed on ('technichub', '3.6.0b2', 'ci-build-3639-v3.6.0b2-33-g8137ff5e on 2024-12-05')

with program magweg.py:

import magweg
print(0300)

reports:

Traceback (most recent call last):
  File "magweg.py", line 2, in <module>
ImportError: no module named 'magweg'

Without the leading zero:

import magweg
print(10300)

reports (twice due to the import):

10300
10300

Problem in pre-parse?

@laurensvalk
Copy link
Member

It sounds like this might be a similar issue to:

Apparently, this is caused by the Python parser that we are using to find resolve imports. https://github.com/pybricks/python-program-analysis

Originally posted by @dlech in #1804 (comment)

@laurensvalk laurensvalk added bug Something isn't working software: pybricks-code Issues with https://code.pybricks.com application and removed triage Issues that have not been triaged yet labels Dec 19, 2024
@BertLindeman
Copy link

BertLindeman commented Dec 19, 2024

@a10036gt in python 3 the leading zero poses a syntax error:

    print(0300)
          ^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers

If you really want to use an octal value it should be print(0o300)

@a10036gt
Copy link
Author

@BertLindeman Yes I know it's a syntax error, but we find this big because while students tuning a huge program they wrongly have a leading zero (like adjust parameters but typos), but the error throw out is something not import, so they use a bit of time to find out what happened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working software: pybricks-code Issues with https://code.pybricks.com application
Projects
None yet
Development

No branches or pull requests

3 participants