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

Use ruff as linter and formatter #1012

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

Use ruff as linter and formatter #1012

wants to merge 5 commits into from

Conversation

larsevj
Copy link
Contributor

@larsevj larsevj commented Aug 25, 2024

I commented out the Isort rules, as they messed up and you run into errors with circular imports and partially imported modules.
Defer the fix of that to another issue or pr.

@larsevj larsevj force-pushed the use_ruff_2 branch 4 times, most recently from cf3d5fc to eff4e60 Compare August 26, 2024 10:50
@larsevj larsevj marked this pull request as ready for review August 26, 2024 10:56
@larsevj larsevj requested a review from eivindjahren August 26, 2024 10:56
@larsevj larsevj force-pushed the use_ruff_2 branch 4 times, most recently from 8672735 to 825bbb9 Compare August 29, 2024 12:05
Copy link
Collaborator

@eivindjahren eivindjahren left a comment

Choose a reason for hiding this comment

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

The test coverage of resdata is not great, and from earlier experiences, sweaping changes like this has a high risk of introducing bugs. I think we should increase the test coverage for the code being changed and ensure we don't change any behavior. I marked up a couple of cases where I know the test data is difficult to generate and I will have a look at helping out on those.

if monitor_survey is not None:
if not monitor_survey in self:
raise KeyError("No such survey: %s" % monitor_survey)
if monitor_survey is not None and not monitor_survey in self:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The tests never check that these KeyErrors is raised under correct conditions. I think before merging this PR, we should add some tests that check that we don't accidentally change the condition for which the KeyError is raised.

raise ValueError("Invalid I1:%d" % I1)
if I2 < 0 or I2 >= self.nx:
if I2 < 0 or self.nx <= I2:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Except for the ValueError on line 227 and on line 232, these ValueErrors are not checked in the tests. I think before merging this PR, we should add some tests that check that we don't accidentally change the condition for which the ValueError is raised.

polyline = target.getPolyline(k)
else:
polyline = target
polyline = target.getPolyline(k) if isinstance(target, Fault) else target
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the tests, target is always a Fault. We should add a test for which target is a polyline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should probably be a check in resdata if input is neither a Fault nor polyline.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case I think you will get a TypeError later on. Could just try it and then create a better error message.

name = "Extend:%s" % self.getName()
else:
name = None
name = "Extend:%s" % self.getName() if self.getName() else None
Copy link
Collaborator

Choose a reason for hiding this comment

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

extend_to_b_box is never called in the tests. We should add some tests for it before changing this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see that there is a similar extendToBBox for cpolylines, so could probably have removed most of this function, but can write some tests for it anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

other_polyline = other.getPolyline(k)
else:
other_polyline = other
other_polyline = other.getPolyline(k) if isinstance(other, Fault) else other
Copy link
Collaborator

Choose a reason for hiding this comment

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

end_join is never called with other being a Fault. We should add a test for that so we don't accidentally change the function.

@@ -120,16 +120,16 @@ def __init__(self, default_value=None, initial_size=0):
else:
try:
default = CTime(default_value)
except:
except Exception as err:
raise ValueError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This ValueError is never raised from the tests.

@@ -355,7 +350,7 @@ def __rmul__(self, factor):
return self.__mul__(factor)

def __div__(self, divisor):
if isinstance(divisor, int) or isinstance(divisor, float):
if isinstance(divisor, (int, float)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This condition is never false in the tests.

@@ -396,11 +391,10 @@ def assign(self, value):
if type(self) == type(value):
# This is a copy operation
self._memcpy(value)
elif isinstance(value, (int, float)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This condition is never false in the tests.

python/resdata/util/util/version.py Outdated Show resolved Hide resolved
name = "%s" % name
else:
name = "[no name]"
name = "%s" % name if name else "[no name]"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This repr is never called in the tests.

@eivindjahren eivindjahren added the christmas-review Issues and PRs for Christmas review label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
christmas-review Issues and PRs for Christmas review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants