Make indexers work for interface objects by danabr · Pull Request #1246 · pythonnet/pythonnet
Conversation
What does this implement/fix? Explain your changes.
Makes the following work instead of throwing an exception:
from System.Collections.Generic import Dictionary, IDictionary d = IDictionary[str, str](Dictionary[str, str]()) d["one"] = "1" assert d["one"] == "1"
Does this close any currently open issues?
No
Checklist
Check all those that are applicable and complete.
Codecov Report
Merging #1246 into master will not change coverage.
The diff coverage isn/a.
@@ Coverage Diff @@ ## master #1246 +/- ## ======================================= Coverage 86.25% 86.25% ======================================= Files 1 1 Lines 291 291 ======================================= Hits 251 251 Misses 40 40
| Flag | Coverage Δ | |
|---|---|---|
| #setup_linux | 64.94% <ø> (ø) |
|
| #setup_windows | 72.50% <ø> (ø) |
Flags with carried forward coverage won't be shown. Click here to find out more.
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 03cf4ac...12fdaab. Read the comment docs.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things related to each other:
- Please, add a negative test (if one does not exist yet). E.g. construct an empty
System.Object, and ensure Python can't index it for read or write. - Consider only assigning
mp*_subscriptslots only when the type actually supports indexing like you did withtp_next.
Makes the following work instead of throwing an exception: ```python from System.Collections.Generic import Dictionary, IDictionary d = IDictionary[str, str](Dictionary[str, str]()) d["one"] = "1" assert d["one"] == "1" ```
I've added the two things you asked for.
The erasing of the slots is ugly. We should consider moving InitializeSlots into ManagedObject and its descendants instead, so that you would just do impl.InitializeSlots(type), and each type could handle its own initialization.
Great, thanks!
I agree on InitializeSlots. If you'd like to work on that, you can start with a draft request demonstrating an approach for any one kind of ManagedObject (it does not have to pass tests or compile). Otherwise we'll just keep that in mind.
Overall it might make sense to move the majority of TypeManager type creation functionality into ManagedObject and deriving classes, including PyType construction. But we better do that along with the migration to PyType_FromSpec.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters