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
Add types to argparse and alt_getopt #4497
Conversation
library/lua/gui/dwarfmode.lua
Outdated
@@ -36,6 +36,7 @@ function getPanelLayout() | |||
} | |||
end | |||
|
|||
---@return global.T_cursor|nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't actually return a T_cursor, it returns a standard Lua table with the same fields as T_cursor.
@@ -57,11 +60,16 @@ local function get_opt_map(opts) | |||
return options | |||
end | |||
|
|||
---@param opt string|integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opt can only be a string at this point (but I see that the more permissive type might be needed because it can be string|integer in other contexts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, I believe.
@@ -45,6 +45,9 @@ | |||
|
|||
local _ENV = mkmodule('3rdparty.alt_getopt') | |||
|
|||
---@nodiscard | |||
---@param opts string | |||
---@return table<string, string|integer> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
table value is always an integer (but I see that the more permissive type might be needed because it can be string|integer in other contexts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is one of a few "just has to be truthy" fields.
---@nodiscard | ||
---@param args string[] e.g, { ... } | ||
---@param sh_opts string e.g., 'ak:hv' | ||
---@param long_opts table<string, string|integer> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this a table<string, string>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processArgsGetopt
assigns a truthy 1 or 0 to it. So I guess it kind of like the other "just has to be a truthy" fields.
library/lua/3rdparty/alt_getopt.lua
Outdated
---@param args string[] | ||
---@param sh_opts string | ||
---@param long_opts string[] | ||
---@return table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specifically, table<string, string|integer>, right?
library/lua/argparse.lua
Outdated
@@ -153,6 +180,10 @@ function numberList(arg, arg_name, list_length) | |||
return strings | |||
end | |||
|
|||
---@nodiscard | |||
---@param arg integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arg is string|integer (but is likely to be a string)
library/lua/argparse.lua
Outdated
---@nodiscard | ||
---@param arg integer | ||
---@param arg_name? string | ||
---@return number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specifically an integer, if that matters
library/lua/argparse.lua
Outdated
@@ -162,6 +193,10 @@ function positiveInt(arg, arg_name) | |||
return val | |||
end | |||
|
|||
---@nodiscard | |||
---@param arg integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string|integer
library/lua/argparse.lua
Outdated
---@nodiscard | ||
---@param arg integer | ||
---@param arg_name? string | ||
---@return number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
integer
library/lua/argparse.lua
Outdated
---@param arg string|'here' | ||
---@param arg_name? string | ||
---@param skip_validation? boolean | ||
---@return global.T_cursor|coord |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always a coord, never a T_cursor
This PR adds type annotations for argparse (and to alt_getopt for further support) and a few odd functions that were beneficial.
get_opts
function,optargs
are unusedgetCursorPos
uses the df-structures global even though it doesn't really fit there, this raises a topic about creating separate types for things likecoords
that can be re-used outside of the context of structures---@class argparse.class
and will likely extend that to the structures, as well as other modules, in the future.