FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make indexers work for interface objects by danabr · Pull Request #1246 · pythonnet/pythonnet · GitHub

Make indexers work for interface objects - #1246

Merged
lostmsu merged 2 commits into
pythonnet:masterfrom
danabr:interface-indexers
Oct 6, 2020
Merged

Make indexers work for interface objects#1246
lostmsu merged 2 commits into
pythonnet:masterfrom
danabr:interface-indexers

Conversation

danabr commented Oct 5, 2020
edited
Loading

Copy link
Copy Markdown
Contributor

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.

  • 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-commenter commented Oct 5, 2020
edited
Loading

Copy link
Copy Markdown

Codecov Report

Merging #1246 into master will not change coverage.
The diff coverage is n/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.

lostmsu left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Two things related to each other:

  1. 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.
  2. Consider only assigning mp*_subscript slots only when the type actually supports indexing like you did with tp_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"
```
danabr force-pushed the interface-indexers branch from ee9b958 to cce614f Compare October 6, 2020 05:32

danabr commented Oct 6, 2020

Copy link
Copy Markdown
Contributor Author

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.

danabr force-pushed the interface-indexers branch from cce614f to a182b68 Compare October 6, 2020 11:05
danabr force-pushed the interface-indexers branch from a182b68 to 12fdaab Compare October 6, 2020 12:17

lostmsu commented Oct 6, 2020

Copy link
Copy Markdown
Member

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.

lostmsu merged commit f808166 into pythonnet:master Oct 6, 2020
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
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


Back | FazBrowse Home | New Git URL