-
Notifications
You must be signed in to change notification settings - Fork 757
Codec groups: EncoderGroup and DecoderGroup #1085
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
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.
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.
There was a problem hiding this comment.
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.
src/embed_tests/Codecs.cs
Outdated
public PyObject TryEncode(object value) => this.GetRawPythonProxy(); | ||
} | ||
|
||
class FakeDecoder<TTarget> : IPyObjectDecoder |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
* 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.