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 B008 errors #6952

Merged
merged 3 commits into from
Nov 15, 2024
Merged

Conversation

janasangeetha
Copy link
Contributor

@@ -140,8 +140,10 @@ def verify_beam_pipeline_arg(a: int) -> OutputDict(b=float): # pytype: disable=

def verify_beam_pipeline_arg_non_none_default_value(
a: int,
beam_pipeline: BeamComponentParameter[beam.Pipeline] = beam.Pipeline(),
beam_pipeline: BeamComponentParameter[beam.Pipeline] = 0,
Copy link
Member

Choose a reason for hiding this comment

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

beam_pipeline: BeamComponentParameter[beam.Pipeline] = None looks better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the test case is to verify the default value to not none, the test case fails with below error:
FAILED tfx/dsl/component/experimental/decorators_test.py::ComponentDecoratorTest::testBeamPipelineDefaultIsNotNoneFails - TypeError: Argument a should be a Channel of type <class 'tfx.types.standard_artifacts.Integer'> (got 1)
Hence I have assigned default value as 0.

Copy link
Member

@lego0901 lego0901 Nov 6, 2024

Choose a reason for hiding this comment

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

Oh I see. The typing error is pretty clear. You cannot assign an integer to other type.

If it is to avoid B008, then how's about doing it in this way?

_TestBeamPipelineArgs = ['--my_testing_beam_pipeline_args=foo']
_TestEmptyBeamPipeline = beam.Pipeline()  # <- Newly added

...

def verify_beam_pipeline_arg_non_none_default_value(
    a: int,
    beam_pipeline: BeamComponentParameter[beam.Pipeline] = _TestEmptyBeamPipeline,
) -> OutputDict(b=float):  # pytype: disable=invalid-annotation,wrong-arg-types
  del beam_pipeline
  return {'b': float(a)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! That works. I have updated.

@@ -140,8 +140,10 @@ def verify_beam_pipeline_arg(a: int) -> TypedDict('Output6', dict(b=float)): #

def verify_beam_pipeline_arg_non_none_default_value(
a: int,
beam_pipeline: BeamComponentParameter[beam.Pipeline] = beam.Pipeline(),
beam_pipeline: BeamComponentParameter[beam.Pipeline] = 0,
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error:
FAILED tfx/dsl/component/experimental/decorators_typeddict_test.py::ComponentDecoratorTest::testBeamPipelineDefaultIsNotNoneFails - TypeError: Argument a should be a Channel of type <class 'tfx.types.standard_artifacts.Integer'> (got 1)

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

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! Just added some minor comments

@keerthanakadiri keerthanakadiri self-assigned this Nov 7, 2024
@lego0901 lego0901 merged commit 7615e5a 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants