Skip to content

Improve compatibility between turtle.FormattedTuple and stdlib's turtle.Vec2D (turtle star) - #2911

Merged
PierreQuentel merged 1 commit into
brython-dev:masterfrom
m-aciek:patch-1
Aug 23, 2026
Merged

Improve compatibility between turtle.FormattedTuple and stdlib's turtle.Vec2D (turtle star)#2911
PierreQuentel merged 1 commit into
brython-dev:masterfrom
m-aciek:patch-1

Conversation

@m-aciek

@m-aciek m-aciek commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Turtle module docs intro contains following script for drawing turtle star:

color('red')
fillcolor('yellow')

begin_fill()
while True:
    forward(200)
    left(170)
    if abs(pos()) < 1:
        break

end_fill()
done()

It draws correctly with tkinter, but abs(pos()) < 1 fails with TypeError: Bad operand type for abs(): 'FormattedTuple' for Brython (and Basthon).

Fix by copying over __abs__ method implementation for stdlib. __abs__ method returns the absolute value of the point.

Add __abs__ method to return the absolute value of the point.
@m-aciek

m-aciek commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

With the same change in Basthon turtle source I was able to draw the SVG:
Zrzut ekranu 2026-08-5 o 12 22 20

cc @bearney74

@m-aciek

m-aciek commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Slightly related: I also opened a PR to simplify this docs fragment to not use the abs(), led by motivation of easier reader comprehension.

@m-aciek

m-aciek commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

cc @casatir -- the same issue applies to Basthon turtle, but I don't have access to post a pull request for it.

@PierreQuentel
PierreQuentel merged commit 33f8524 into brython-dev:master Aug 23, 2026
@PierreQuentel

Copy link
Copy Markdown
Contributor

Thanks for the PR Maciej, and sorry for the late reaction, August is more dedicated to holidays and family !

@m-aciek

m-aciek commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Thank you! No worries. Just to mention in the meantime we've simplified code example in the turtle tutorial.

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

Successfully merging this pull request may close these issues.

2 participants