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

perf: support for custom action in config parser #361

Merged
merged 2 commits into from
Sep 16, 2024

Conversation

daejunpark
Copy link
Collaborator

@daejunpark daejunpark commented Sep 14, 2024

add support for custom action in halmos config. this allows structural option values (e.g., --array-length) to be parsed at the time of config creation.

note: since the config object is frozen, it is nontrivial to extend or update the config with parsing raw string values after config has been created. also, since config objects are re-generated to override further configurations, it's more convenient to parse raw string through argparser.

@daejunpark daejunpark marked this pull request as ready for review September 14, 2024 01:37
@@ -45,10 +47,39 @@ def arg(
"short": short,
"countable": countable,
"global_default_str": global_default_str,
"action": action,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

would it be better to use a different name, e.g., custom_action, to avoid potential name clashes? it might be fine as the name choices is also used here, but let me know if you have any concerns.

Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure I follow, name clash with what?

I'm ok with custom_action, but don't love the "action" nomenclature. If this is about parsing, what about parser?

Copy link
Collaborator

Choose a reason for hiding this comment

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

parser is even more overloaded, ignore that. Either action or custom_action works IMO, I wouldn't worry about name clashes at that level (I thought this was a concern about shadowing)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay, i will stick with action.

},
)


class ParseCSV(argparse.Action):
Copy link
Collaborator

Choose a reason for hiding this comment

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

what do we get by subclassing argparse.Action?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah I see we pass it to the generated argparse parser. Pretty cool!

@@ -45,10 +47,39 @@ def arg(
"short": short,
"countable": countable,
"global_default_str": global_default_str,
"action": action,
Copy link
Collaborator

Choose a reason for hiding this comment

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

parser is even more overloaded, ignore that. Either action or custom_action works IMO, I wouldn't worry about name clashes at that level (I thought this was a concern about shadowing)

},
)


class ParseCSV(argparse.Action):
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah I see we pass it to the generated argparse parser. Pretty cool!

@daejunpark daejunpark merged commit 1e850a6 into main Sep 16, 2024
57 checks passed
@daejunpark daejunpark deleted the perf/custom-action-argparser branch September 16, 2024 17:09
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