Codec groups: EncoderGroup and DecoderGroup#1085
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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);
| using System.Linq; | ||
| using NUnit.Framework; | ||
| using Python.Runtime; | ||
| using Python.Runtime.Codecs; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/embed_tests/Codecs.cs
Outdated
| public PyObject TryEncode(object value) => this.GetRawPythonProxy(); | ||
| } | ||
|
|
||
| class FakeDecoder<TTarget> : IPyObjectDecoder |
There was a problem hiding this comment.
Maybe give this a few lines of documentation to make it easier to follow the tests.
There was a problem hiding this comment.
@filmor renamed classes to make their behavior more clear, and added xmldoc.
* 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);
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:
Then in a program using that library:
Does this close any currently open issues?
No
Checklist
Check all those that are applicable and complete.