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

dict() constructor should accept mappings #198

Open
brandjon opened this issue Jun 24, 2021 · 1 comment
Open

dict() constructor should accept mappings #198

brandjon opened this issue Jun 24, 2021 · 1 comment

Comments

@brandjon
Copy link
Member

The current verbiage is:

dict creates a dictionary. It accepts up to one positional argument, which is interpreted as an iterable of two-element sequences (pairs), each specifying a key/value pair in the resulting dictionary.

In reality, the Java implementation allows the positional argument to also be another dictionary, in which case the entries of that dictionary are included in the new one. Note that this is a distinct case because iterating over dictionaries yields their keys, not their key-value pairs.

The Java implementation's behavior is consistent with Python. But in reality, it should be generalized to also extend to other user-defined mapping types. The concept of Mapping is already defined in the spec.

@brandjon
Copy link
Member Author

For reference, in Python, the criteria for treating the positional argument to dict() as a mapping rather than an iterable appears to be that it has the keys() and __getitem__() methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant