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 Ruff rule B027 and B024 #6950

Merged
merged 8 commits into from
Nov 15, 2024

Conversation

janasangeetha
Copy link
Contributor

@janasangeetha janasangeetha commented Nov 4, 2024

Fix Ruff rules
#6943

@janasangeetha janasangeetha changed the title Fix Ruff rule B027 Fix Ruff rule B027 and B024 Nov 4, 2024
"""Executor Operator specific logic to clean up after it is stopped."""
pass

class BaseExecutorOperator(ParentBaseExecutorOperator):
Copy link
Member

Choose a reason for hiding this comment

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

Is this really needed? I think it is sufficient to have handle_stop to be an abstractmethod, without needing to introduce ParentBaseExecutorOperator. I guess it is normal to have handle_stop implementation for any class that inherits BaseExecutorOperator.

def _before_run(self, runner: tfx_runner.TfxRunner,
pipeline: Union[pipeline_pb2.Pipeline, tfx_pipeline.Pipeline],
context: MutableMapping[str, Any]) -> None:
pass

@abc.abstractmethod
Copy link
Member

Choose a reason for hiding this comment

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

Same here (and above _before_run). I believe all we need is @abc.abstractmethod decorators.

Copy link
Member

Choose a reason for hiding this comment

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

ditto

@lego0901
Copy link
Member

lego0901 commented Nov 5, 2024

SG for B024. Please tackle me if anything is wrong with my comments on B027. Thanks!

@janasangeetha
Copy link
Contributor Author

@lego0901 On adding @abc.abstractmethod decorators, we observe failure in test cases #6942.
We should define the abstract methods of an abstract class in a child class. Hence, the parent classes are introduced.

@lego0901
Copy link
Member

lego0901 commented Nov 5, 2024

I see.. Thanks. Indeed those methods are intentionally no-ops unless they are overridden.
Is there any way to suppress those Ruff warnings similar to B024? They are clearly not abstract methods, but adding a unnecessary chain seems not good for maintenance.

@@ -30,7 +30,7 @@ class SystemArtifact(abc.ABC):
The subclasses, e.g, Dataset, Model, Statistics, e.t.c, match the MLMD types
from third_party/ml_metadata/metadata_store/mlmd_types.py.
"""

# noqa: B024
Copy link
Member

Choose a reason for hiding this comment

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

This wasn't effective. Please try it out with

class SystemArtifact(abc.ABC):  # noqa: B024

@@ -30,7 +30,7 @@ class SystemExecution(abc.ABC):
The subclasses, e.g, Train, Transform, Process, e.t.c, match the MLMD types
from third_party/ml_metadata/metadata_store/mlmd_types.py.
"""

# noqa: B024
Copy link
Member

Choose a reason for hiding this comment

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

ditto

The output from executor.
"""
pass

def handle_stop(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

You can suppress B027 check via

  def handle_stop(self) -> None:  # noqa: B027

@lego0901
Copy link
Member

lego0901 commented Nov 5, 2024

Please make sure that everything is clear if you run

ruff check tfx --exclude tfx/examples/airflow_workshop/taxi/notebooks/*.ipynb --select "B024,B027"

Thanks!

@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Base class to patch DagRunner classes in TFX CLI."""

#ruff: noqa: B027
Copy link
Member

Choose a reason for hiding this comment

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

Why do you prefer global noqa over specific lines? I personally lean toward using # noqa: B027 only for specific lines because new contributors could ignore all B027 rules on the same file, which isn't desirable for the code health.

@@ -84,6 +84,6 @@ def with_execution_watcher(
self._execution_watcher_address = execution_watcher_address
return self

def handle_stop(self) -> None:
def handle_stop(self) -> None:# noqa: B027
Copy link
Member

Choose a reason for hiding this comment

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

And also a nit comment; as a coding convention, we were using two spaces before any comment #. This was warned when we are on the internal Google land, but I am not sure if it is captured by the linter here.

@smokestacklightnin could you let me know if this comment style is acceptable by the linter? pylint --rcfile ./pylintrc tfx/types/system_executions.py didn't warn me

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe the number of spaces matters. I tried with zero, one, and two spaces, and all three options passed ruff check.

Copy link
Member

@lego0901 lego0901 left a comment

Choose a reason for hiding this comment

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

Thanks!

@lego0901 lego0901 merged commit 8393d14 into tensorflow:master Nov 15, 2024
7 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants