erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.68k stars 55 forks source link

docs: fix `doc/scripts/sync_to_translation_status.er` and update some actions #508

Open toddlerer opened 5 months ago

toddlerer commented 5 months ago

I encountered a bug that seemed to be caused by non-intuitive behavior of default arguments when using a recursive function in Python, so I fixed it by switching to a for loop.

@mtshiba

mtshiba commented 5 months ago

Although not directly related to this PR, I enhanced the type definitions of os.path and added a method called Str.from that does the same thing as Python's self[nth:]. So, mylib.{d.er, py} should no longer be necessary from the next release, which will be released next week.

toddlerer commented 5 months ago

@mtshiba Thank you for your prompt response. I tried replacing mylib.{d.er, py} with the latest commit on the main branch, and I was able to replace almost everything. However, I couldn't replace the parts using __file__, and it seems that __file__ is not available when running with erg run. (It worked when I transpiled with erg transpile and then ran the Python file.)

print! __file__
$ erg test.er    
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "test.er", line -1, in <module>
NameError: name '__file__' is not defined. Did you mean: '__name__'?

In this case, I am using it to obtain the directory of the currently executing file and set it as the current directory.

os = pyimport "os"

cwd = os.path.dirname! __file__
os.chdir! cwd
mtshiba commented 5 months ago

@mtshiba Thank you for your prompt response. I tried replacing mylib.{d.er, py} with the latest commit on the main branch, and I was able to replace almost everything. However, I couldn't replace the parts using __file__, and it seems that __file__ is not available when running with erg run. (It worked when I transpiled with erg transpile and then ran the Python file.)

print! __file__
$ erg test.er    
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "test.er", line -1, in <module>
NameError: name '__file__' is not defined. Did you mean: '__name__'?

In this case, I am using it to obtain the directory of the currently executing file and set it as the current directory.

os = pyimport "os"

cwd = os.path.dirname! __file__
os.chdir! cwd

I believe this bug has been fixed in the main branch.