X Tutup
Skip to content

Codec groups: EncoderGroup and DecoderGroup#1085

Merged
filmor merged 2 commits intopythonnet:masterfrom
losttech:PR/CodecGroups
Apr 22, 2020
Merged

Codec groups: EncoderGroup and DecoderGroup#1085
filmor merged 2 commits intopythonnet:masterfrom
losttech:PR/CodecGroups

Conversation

@lostmsu
Copy link
Copy Markdown
Member

@lostmsu lostmsu commented Mar 10, 2020

What does this implement/fix? Explain your changes.

These classes would help to manage codec layers. For example, a library could register its own codecs, but also allow anyone to inject their codecs before library's own:

public static EncoderGroup BeforeLibraryEncoders { get; }
    = new EncoderGroup();

LibraryRegisterCodecs()
{
  PyObjectConversions.RegisterEncoder(BeforeLibraryEncoders);
  PyObjectConversions.RegisterEncoder(LibraryEncoder.Instance);
}

Then in a program using that library:

Library.BeforeLibraryEncoders.Add(preencoder);

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

@lostmsu lostmsu added this to the 2.4.1 milestone Mar 10, 2020
@codecov-io
Copy link
Copy Markdown

codecov-io commented Mar 10, 2020

Codecov Report

Merging #1085 into master will increase coverage by 0.30%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1085      +/-   ##
==========================================
+ Coverage   86.75%   87.05%   +0.30%     
==========================================
  Files           1        1              
  Lines         302      340      +38     
==========================================
+ Hits          262      296      +34     
- Misses         40       44       +4     
Flag Coverage Δ
#setup_linux 65.56% <ø> (ø)
#setup_windows 73.82% <ø> (+2.30%) ⬆️
Impacted Files Coverage Δ
setup.py 87.05% <0.00%> (+0.30%) ⬆️

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 d145ab1...d0d0ce8. Read the comment docs.

These classes would help to manage codec layers. For example, a library could register its own codecs, but also allow anyone to inject their codecs before library's own:

public static EncoderGroup BeforeLibraryEncoders { get; }
    = new EncoderGroup();

void LibraryRegisterCodecs(){
  PyObjectConversions.RegisterEncoder(BeforeLibraryEncoders);
  PyObjectConversions.RegisterEncoder(LibraryEncoder.Instance);
}

Then in a program using that library:
Library.BeforeLibraryEncoders.Encoders.Add(preencoder);
@filmor filmor self-assigned this Apr 9, 2020
using System.Linq;
using NUnit.Framework;
using Python.Runtime;
using Python.Runtime.Codecs;
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.

While I don't have a particular problem with this, why are you using this style? It's not in use in the established codebase and I have never seen it outside either.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Imagine we use a System.Uri a lot. At some point in the future we decide to take a dependency (or introduce our own) on something, that has Python.Uri class, which we might not need ourselves, but it is public.

With

using System;

namespace Python.Runtime {
  class SomeClass {
    Uri uriField;
  }
}

the uriField will silently change its type from System.Uri to Python.Uri.

If the using System; is inside namespace Python.Runtime, that won't happen.

public PyObject TryEncode(object value) => this.GetRawPythonProxy();
}

class FakeDecoder<TTarget> : IPyObjectDecoder
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.

Maybe give this a few lines of documentation to make it easier to follow the tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@filmor renamed classes to make their behavior more clear, and added xmldoc.

@lostmsu lostmsu requested a review from filmor April 14, 2020 04:02
@filmor filmor merged commit 555f562 into pythonnet:master Apr 22, 2020
@lostmsu lostmsu modified the milestones: 2.4.1, 2.5.0 Apr 23, 2020
AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this pull request Jun 29, 2020
* Added Codecs: EncoderGroup and DecoderGroup

These classes would help to manage codec layers. For example, a library could register its own codecs, but also allow anyone to inject their codecs before library's own:

public static EncoderGroup BeforeLibraryEncoders { get; }
    = new EncoderGroup();

void LibraryRegisterCodecs(){
  PyObjectConversions.RegisterEncoder(BeforeLibraryEncoders);
  PyObjectConversions.RegisterEncoder(LibraryEncoder.Instance);
}

Then in a program using that library:
Library.BeforeLibraryEncoders.Encoders.Add(preencoder);
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

X Tutup