Skip to content

Add C# Dictionary to Python Dict conversion #972

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

Closed
wants to merge 3 commits into from

Conversation

thesn10
Copy link
Contributor

@thesn10 thesn10 commented Oct 18, 2019

What does this implement/fix? Explain your changes.

You can now convert a C# IDictionary to a Python Dict by calling ToPython()

Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("hello", "world");

dynamic d = dict.ToPython();
string value = d.get("hello", "");

Does this close any currently open issues?

No, but it is progress for #623

Any other comments?

Do i really have to include a test for this? I mean, the TestConverter.cs file doesnt have any tests for other similar types like IList at all.

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

@codecov-io
Copy link

codecov-io commented Oct 18, 2019

Codecov Report

Merging #972 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #972   +/-   ##
=======================================
  Coverage   86.71%   86.71%           
=======================================
  Files           1        1           
  Lines         301      301           
=======================================
  Hits          261      261           
  Misses         40       40
Flag Coverage Δ
#setup_linux 65.44% <ø> (ø) ⬆️
#setup_windows 71.42% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a9457f...6b43096. Read the comment docs.

@filmor
Copy link
Member

filmor commented Oct 18, 2019

Thanks a lot for this. However, as noted in #963, I'd really like to get away from the implicit conversions and instead allow the wrapped C# object to act like a Python dict without actually performing the conversion (unless explicitly requested).

@thesn10
Copy link
Contributor Author

thesn10 commented Oct 19, 2019

Oh thats nice :) Will it take long until the implicit conversions get replaced? Because maybe this PR could still be a temporary solution to allow the use of IDictionary as a python dict.

In #963 you only mention IEnumerable and ICollection. Will there be a solution for IDictionary too?

@thesn10 thesn10 closed this Mar 27, 2020
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.

3 participants