Change to syntax to compile?

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
RewindTheGame
Regular
Posts: 62
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Change to syntax to compile?

#1 Post by RewindTheGame »

I know I've seen this in an update log somewhere, but I can't for the life of me find it now. Moving up from RenPy 8.1.3 to the latest version, I get this error in the inventory code. I think it's something to do with the way the -> format has changed and simply requires a syntax change to some lines of code, but I can't remember where I saw the fix and can't find it now. Can anyone help?

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/inventory.rpy", line 676, in script
    init python:
  File "game/inventory.rpy", line 676, in script
    init python:
  File "game/inventory.rpy", line 684, in <module>
    def findLast(l: list, val) -> Optional[int]:
NameError: name 'Optional' is not defined

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Change to syntax to compile?

#2 Post by jeffster »

Type hints give that error in the latest builds. I think it's just a temporary development thing. Just use some stable release instead of "nightly" or whatever you are using.

Otherwise, just delete those type hints - here parts between ) and :.

Instead of

Code: Select all

    def findLast(l: list, val) -> Optional[int]:
this should work:

Code: Select all

    def findLast(l: list, val):
or this:

Code: Select all

    def findLast(l, val):

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Change to syntax to compile?

#3 Post by jeffster »

RewindTheGame wrote: Mon Mar 25, 2024 10:20 am I know I've seen this in an update log somewhere, but I can't for the life of me find it now. Moving up from RenPy 8.1.3 to the latest version, I get this error in the inventory code.
PS. Oops, no, I believe that's a bug in Ren'Py.
viewtopic.php?t=68117

For now the way to get rid of those errors is either use Ren'Py 8.1, or delete those type hints from the script (there are just a few of them).

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Change to syntax to compile?

#4 Post by PyTom »

You probably need:

Code: Select all

init python:
    from typing import Optional
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Change to syntax to compile?

#5 Post by jeffster »

PyTom wrote: Mon Apr 01, 2024 2:08 am You probably need:

Code: Select all

init python:
    from typing import Optional
I wonder why Ren'Py 8.1 didn't need that import line. Now it needs

Code: Select all

init python:
    from typing import Optional, Union

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]