Skip to content
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

Allow Metadata to be updated with kwargs #119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

prayush
Copy link

@prayush prayush commented Dec 23, 2024

The current Metadata class disallows update(...) with keyword arguments, which its base class OrderedDict allows. One has to:

import sxs
x = sxs.Metadata()
x.update(dict(reference-time=100))

instead of

x.update(reference-time=100)

This PR will enable the latter syntax, aligning the Metadata class closer to its base class.


📚 Documentation preview 📚: https://sxs--119.org.readthedocs.build/en/119/

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Project coverage is 42.62%. Comparing base (f7b8fc0) to head (bc19e1c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sxs/metadata/metadata.py 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #119      +/-   ##
==========================================
- Coverage   42.65%   42.62%   -0.03%     
==========================================
  Files          80       80              
  Lines        6731     6735       +4     
  Branches     1075     1077       +2     
==========================================
  Hits         2871     2871              
- Misses       3614     3618       +4     
  Partials      246      246              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@duetosymmetry
Copy link
Member

This seems like a nice idea — I think we should follow the pattern of the builtin container. The documentation for dict.update says:

Help on built-in function update:

update(...) method of builtins.dict instance
    D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
    If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]
    If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
    In either case, this is followed by: for k in F:  D[k] = F[k]

this means that the kwargs assignment should be done afterwards. And, I think we don't need to check isinstance — we can just do what the documentation suggests, trying with keys().

@duetosymmetry
Copy link
Member

@moble can you figure out what's wrong with the deps in the tests? It seems to work on some platforms but not others. It doesn't have anything to do with Prayush's code

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