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

Value semantics #51

Merged
merged 4 commits into from
Nov 16, 2019
Merged

Value semantics #51

merged 4 commits into from
Nov 16, 2019

Conversation

lichray
Copy link
Contributor

@lichray lichray commented Nov 16, 2019

Python argparse.ArgumentParser is stateless, so adding parents is only inheriting argument configurations. This is equivalent to having value semantics.

argparse::ArgumentParser is stateful. Instead of returning parsed states, parse_args changes the parser's own states. And I think we should also deliver value semantics, that is, parse_args in child parser does not change parents' parsing states, and parse_args in a parser copy does not change the parsing states parser that was copied from.

Updated the docs to use the term "common" rather than "shared" to clarify the intention.

Strictly speaking this is a runtime breaking change. But the current behavior is undocumented, untested, and I doubt anybody is relying on that in real code.

The proposed change also eliminates the uses of shared_ptr. It maintains two linked lists (not worse than two vectors of shared_ptrs :) of Arguments, and index them by pointing the keys into Argument's own storage for names, and the values into list iterators.

fixes: #50

@p-ranav p-ranav merged commit 439b2d0 into p-ranav:master Nov 16, 2019
@lichray lichray deleted the value-semantics branch November 17, 2019 03:03
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.

Question: parent parser and value semantics
2 participants