Skip to content

Lupa stubs: #14359

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Lupa stubs: #14359

wants to merge 1 commit into from

Conversation

jmarianer
Copy link

@jmarianer jmarianer commented Jul 1, 2025

Support get/set/del from Lua tables.
Lua table values are all Any because we can't typecheck across language boundaries.
Support unpack_returned_tuples in the LuaRuntime constructor.

@jmarianer
Copy link
Author

The failing check is easy enough to fix, but I found a possible way to get around the Any and I need to test it, so I'll be a while.

This comment has been minimized.

2 similar comments

This comment has been minimized.

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, remarks below. Please note that I only left remarks on the first file, but they apply to all files.

@@ -70,8 +73,7 @@ class LuaRuntime:
lua_implementation: Final[str]
lua_version: Final[tuple[int, int]]

# @classmethod
# def __cinit__(cls, unpack_return_tuples: bool) -> None: ...
def __init__(self, /, unpack_returned_tuples: bool, *args: Any) -> None: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that we need a comment for each Any, explaining which types are allowed and/or how it's used.

Comment on lines 47 to 48
LuaKey: TypeAlias = str | int
LuaObject: TypeAlias = _LuaTable | int | str | float | bool | None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, these are not available at runtime, so we need to preface them with an underscore.

You could also consider adding a lupa._types modules where you define these type-check only items and just import them, but that's just an option.

@jmarianer
Copy link
Author

Apologies for sitting on this for so long. I got distracted by something shiny.

I removed the Any from __init__ (I have no idea why I added it and it doesn't seem to be correct), but I readded the Any to LuaObject with a detailed comment. I also added the underscores as you requested.

This comment has been minimized.

Support get/set/del from Lua tables.
Lua table values are all Any because we can't typecheck across language boundaries.
Support unpack_returned_tuples in the LuaRuntime constructor.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Tue Jul 1 16:43:21 2025 -0700
#
# On branch main
# Your branch is ahead of 'origin/main' by 1 commit.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#	modified:   lua51.pyi
#	modified:   lua52.pyi
#	modified:   lua53.pyi
#	modified:   lua54.pyi
#
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "name", "description"  [misc]
+ discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "description", "name"  [misc]
- discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "name", "description"  [misc]
+ discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "description", "name"  [misc]
- discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/hybrid.py:834: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/hybrid.py:858: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/hybrid.py:883: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/hybrid.py:935: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/bot.py:291: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/bot.py:291: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]
- discord/ext/commands/bot.py:315: error: Overlap between argument names and ** TypedDict items: "name", "with_app_command"  [misc]
+ discord/ext/commands/bot.py:315: error: Overlap between argument names and ** TypedDict items: "with_app_command", "name"  [misc]

@jmarianer
Copy link
Author

That mypy note seems irrelevant to this PR (probably just irrelevant in general, but certainly not something we need to worry about here)

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