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

Parse (ignore) typing annotations for define and default #4541

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gouvernathor
Copy link
Member

@Gouvernathor Gouvernathor commented Apr 18, 2023

The following is now allowed :

define a : str = "Hello World"
default b : str = "Hello World"
# define c : int # fails
# default d : int # fails

init python:
    def adj_eileen(attributes):
        return attributes

define config.adjust_attributes["eileen"] : Callable[tuple, tuple] = adj_eileen
define config.adjust_attributes : Dict[str, Callable[tuple, tuple]] |= {"eileen2" : adj_eileen}
define config.after_default_callbacks : List[Callable] += [print]

The annotations are completely ignored, and taking them into account falls solely on the IDE syntax analyzer. I think this is also how it works in Python for non-return and non-parameter annotations ?

This was particularly easy to implement, I'm not sure it's worth it though - if the burden of support falls on the IDE extensions anyway, it might as well use the typing : comments.

@mal
Copy link
Member

mal commented Apr 18, 2023

To me, this seems like potentially opening a hole into which non-programmer creators can fall without intending to, for very limited benefit to a minority (supposition mine) of programmer creators eager for type annotations in RPY files. It also feels a bit strange to add type annotation support to RPY syntax piece-meal, such that the answer to "can I use type annotations in rpy scripts?" is along the lines of "well ... kind of, a bit".

All that aside, I'm not sure if we have "support type annotations in rpy" as a long-term design goal, and perhaps that is the real deciding factor here.

@Gouvernathor
Copy link
Member Author

I think I agree. The Python equivalent actually doesn't ignore the annotation value, even at a module level : the evaluated annotation (or the string, if using the 563 __future__ which is the default in renpy I think) is stored in the __annotations__ dict.
I don't think we should enable annotating short of updating that dict as well - and if we do, we have to make it cooperate with renpy.dynamic variables and called label parameters. So, this would probably be too much work for too little use, at least until proven otherwise.
I'll leave this open, but I don't advise merging without further discussion.

@renpytom
Copy link
Member

I'm sort of thinking we do want annotations at some point, but it should be a comprehensive thing. At the very least, this is going to need to be supported in the VS code plugin, to have any benefit.

@Gouvernathor Gouvernathor added the enhancement A proposed or requested enhancement or improvement to renpy's features. label Jun 21, 2023
@Gouvernathor Gouvernathor marked this pull request as draft July 4, 2023 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A proposed or requested enhancement or improvement to renpy's features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for type annotations to default and define statements
3 participants