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

Proposed fix for issue #50 #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pchampin
Copy link

No description provided.

@pchampin
Copy link
Author

I know that some tests are failing, but they did fail (on my machine at least) on branch master as well, so I do not think that this is due to my patch...

if options['strict']:
raise ValueError("Unrecognized key %s" % key)
elif droppedKeys is not None:
droppedKeys.add(key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Returning a value from a function by modifying an argument is quite an unpopular method with Python programmers. This is a side effect; I would discourage it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@anatoly-scherbakov could you refactor this in a way that still fixes the issue?

Copy link
Author

Choose a reason for hiding this comment

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

@anatoly-scherbakov I disagree that it is inherently a bad thing for a function to mutate one of its arguments, as long as the contract is clear about it.
That being said, I agree that having this "output argument" included in the "options" argument (which is clearly an input argument otherwise), is not great.

I don't consider that changing the return value of expand, in order to include the information about dropped keys, is desirable (it would break existing code).

I believe that a better solution to be to add a 4th parameter to expand: dropped=None. If that parameter is explicitly specified, it must be an (empty?) list, and the contract would be that this list would be populated with the dropped keys.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even if the contract is explicitly specified, this is not what a Python developer is expecting from a library, thus violating the Principle of Least Astonishment.

I have proposed a PR: #186 — but its not ready for merge as it should be really targeted at another PR of mine.

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.

None yet

4 participants