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

fix: Add missing comma in LHEInit fieldnames #282

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

matthewfeickert
Copy link
Member

Fixes the bug in Issue #281

Not sure we have a good test at the moment though.

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.87%. Comparing base (882b1bb) to head (ebfc85e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #282   +/-   ##
=======================================
  Coverage   91.87%   91.87%           
=======================================
  Files           2        2           
  Lines         320      320           
  Branches       64       64           
=======================================
  Hits          294      294           
  Misses         17       17           
  Partials        9        9           
Flag Coverage Δ
unittests-3.10 91.87% <100.00%> (ø)
unittests-3.11 91.87% <100.00%> (ø)
unittests-3.12 91.87% <100.00%> (ø)
unittests-3.13 91.87% <100.00%> (ø)
unittests-3.8 91.87% <100.00%> (ø)
unittests-3.9 91.87% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@APN-Pucky
Copy link
Member

APN-Pucky commented Feb 4, 2025

Here's what we could do. But it seems a bit unnecessary unless we want to restrict the access to the predefined fields (breaking previous "free" behavior). And just defining the list of fields in a second place (tests) seems a bit wasted/stupid as a test. I must say I don't see the point in having the variable fieldnames, unless we loop over it, but maybe there are some builtin dict functions that use it.

class CustomDict(dict):
    fieldnames = ['name', 'age', 'email']

    def __setitem__(self, key, value):
        if key not in self.fieldnames:
            raise KeyError(f"Invalid key: {key}. Allowed keys are {self.fieldnames}")
        super().__setitem__(key, value)
import pytest
from your_module import CustomDict  # Import your class

def test_valid_keys():
    data = CustomDict()
    data['name'] = 'Alice'  # Should work
    data['age'] = 30        # Should work

def test_invalid_key():
    data = CustomDict()
    with pytest.raises(KeyError, match="Invalid key: address"):
        data['address'] = '123 Street'  # Should fail

@eduardo-rodrigues
Copy link
Member

Hello. I tend to agree that a test seems a bit of an overkill. On the other hand I'm sad the bug did not get caught.

@matthewfeickert
Copy link
Member Author

I must say I don't see the point in having the variable fieldnames, unless we loop over it, but maybe there are some builtin dict functions that use it.

I tend to agree that a test seems a bit of an overkill.

Yeah, I agree with you both that adding a test as is seems like a lot of superfluous work. I think we can skip that for this PR and maybe just call this good?

Though I agree with @APN-Pucky that I don't off the top of my head remember why LHEInit has fieldnames

fieldnames = ["initInfo", "procInfo" "weightgroup", "LHEVersion"]

as LHEInit doesn't have a fromstring like LHEInitInfo does

pylhe/src/pylhe/__init__.py

Lines 340 to 342 in 7519967

@classmethod
def fromstring(cls, string):
return cls(**dict(zip(cls.fieldnames, map(float, string.split()))))

and so fieldnames is never used in LHEInit (which is why we've never seen this as a bug).

Ah I guess looking a bit more the fieldnames were added in PR #233 when large components of what used to be LHEInit got moved into LHEInitInfo.

@APN-Pucky @eduardo-rodrigues If we don't explicitly use

fieldnames = ["initInfo", "procInfo" "weightgroup", "LHEVersion"]

then should we keep them at all? (I am going through this quickly while task switching, so I might be missing the obvious.)

Copy link
Member

@eduardo-rodrigues eduardo-rodrigues left a comment

Choose a reason for hiding this comment

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

Let me approve also. Let's get this bug fix in asap and then continue with the other bigger update and improvement from you @APN-Pucky.

(I won't be responsive in the next few days.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants