-
Notifications
You must be signed in to change notification settings - Fork 28
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
Dont dump none entity #31
Conversation
Codecov Report
@@ Coverage Diff @@
## main #31 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 28 28
Branches 5 5
=========================================
Hits 28 28 |
See my comment #23 (comment) I don't agree with this approach. If were to go with this approach we would need:
|
Do you mean it shall be done in order to accept these changes or the approach is invalid at its core so it'd better to be left as it is? |
@samuelcolvin I've covered sequences. But I need to notice that |
This needs to be hidden behind a kwarg as I mentioned above. |
Hi
I am not an expert in python as I've already mentioned but I introduced a optional argument. |
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.
otherwise looks good.
src/lib.rs
Outdated
} else if let Ok(key) = $key.str() { | ||
let key = key.to_string(); | ||
$map.serialize_key(&key)?; | ||
if self.omit_none && $value.is_none() { |
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.
for clarity, and to avoid too many changes, I would prefer this check was done inside the $key.is_none()
if case, rather than as a separate block.
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.
I've tried to eliminate it but as I see there's no easy way?
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.
I changed it a bit e7b8ddd
But it still... not as plain as it'd better be :)
@pytest.mark.parametrize( | ||
'input_obj,output_toml', | ||
[ | ||
({'key': None}, ''), |
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.
what about None
as the key: {None: 1}
?
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.
Good catch.
I did fix it now it doesn't serialize anything.
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.
otherwise, I think makes sense.
"Dictionary key is not a string: {:?}", | ||
$key | ||
))); | ||
let ignore_none_entry = !self.include_none && ($value.is_none() || $key.is_none()); |
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.
I suspect we can do this in a more effecient way, e.g. only check instead the $key.is_none()
logic etc.
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.
Do you mean only check $key.is_none()
?
Because it would break the tests.
src/lib.rs
Outdated
} | ||
|
||
impl<'p, 'a> Serialize for SerializePyObject<'p, 'a> { | ||
impl<'p> SerializePyObject<'p> { | ||
fn new(py: Python<'p>, obj: &'p PyObject, include_none: &PyObject) -> PyResult<Self> { |
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.
not required.
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 not; but isn't it better with it?:)
I mean personally I like 2calls to SerializePyObject::new
rather then 2 constructors
SerializePyObject {
py,
include_none,
obj: obj.extract(py)?,
}
I like the second bullet point from the original proposal #23 (comment). That is, to allow something like a I am Okay with leaving it to the developers to handle loading the A use case would look like this: import rtoml
config = {"addr": "localhost", "port": None}
toml_str = rtoml.dumps(config, none_repr="@none None") # in case "null" is not special enough
# addr = "localhost"
# port = "@none None"
myconfig = rtoml.loads(toml_str, none_repr = "@none None")
# {"addr": "localhost", "port": None} This use case can be found here: https://dynaconf.readthedocs.io/en/docs_223/guides/environment_variables.html#precedence-and-type-casting
We can also allow Since we decide to interpret With this, we can regard it as a superset of I know that a lot of people are wanting to see this with TOML:
And I believe this will raise |
Co-authored-by: Samuel Colvin <[email protected]>
Co-authored-by: Samuel Colvin <[email protected]>
Signed-off-by: Maxim Zhiburt <[email protected]> Co-authored-by: Samuel Colvin <[email protected]>
Signed-off-by: Maxim Zhiburt <[email protected]> Co-authored-by: Samuel Colvin <[email protected]>
Signed-off-by: Maxim Zhiburt <[email protected]>
I agree with @pwwang but logic for detecting a "none value" when parsing toml could wait for a separate PR. |
as agreed above, we would need a different implementation. Also the logic here has changed significantly since #51. |
Hi there,
not an expert in python and neither in your library,
but let's say coincidentally ran into it.
closes #23