Skip to content

Address ruff PLW1508#7962

Closed
mbfreder wants to merge 3 commits intoaws:developfrom
mbfreder:ruff-fix
Closed

Address ruff PLW1508#7962
mbfreder wants to merge 3 commits intoaws:developfrom
mbfreder:ruff-fix

Conversation

@mbfreder
Copy link
Copy Markdown
Contributor

@mbfreder mbfreder commented Apr 2, 2025

Which issue(s) does this change fix?

Address PLW1508. This is needed to merge #7947. Currently, some checks are failing on the PR.

Why is this change necessary?

How does it address the issue?

What side effects does this change have?

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mbfreder mbfreder requested a review from a team as a code owner April 2, 2025 01:19
"""
try:
get_request = requests.get(uri, stream=True, verify=os.environ.get("AWS_CA_BUNDLE", True))
get_request = requests.get(uri, stream=True, verify=os.environ.get("AWS_CA_BUNDLE", "True"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is actually wrong.

requests.get (which behind the scenes just calls requests.request) has this verify parameter that can be either a path to a CA bundle to use or a boolean (https://requests.readthedocs.io/en/latest/api/#requests.request)

So it doesn't really accept a "True" string.

If ruff is complaining about this (which kind of make sense because we're returning two different types from one os.environ.get), we can do maybe

, verify=os.environ.get("AWS_CA_BUNDLE") or True)

Or just add a comment to ignore the rule for this line.

path_mock.unlink.assert_called()
unzip_patch.assert_called_with("layer_zip_path", "output_zip_dir", permission=0o700)
os_patch.environ.get.assert_called_with("AWS_CA_BUNDLE", True)
os_patch.environ.get.assert_called_with("AWS_CA_BUNDLE", "True")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess you'll have to change this test if you change the behavior of os.environ.get in the other file, but this is probably not it.

LOG = logging.getLogger(__name__)

CONTAINER_CONNECTION_TIMEOUT = float(os.environ.get("SAM_CLI_CONTAINER_CONNECTION_TIMEOUT", 20))
CONTAINER_CONNECTION_TIMEOUT = float(os.environ.get("SAM_CLI_CONTAINER_CONNECTION_TIMEOUT", "20"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Just as a small rant incoming, but this code is okay how you did it)

Conceptually this is weird, but I imagine this is the easiest way to do it.

Because we're passing a "20" (string) that will be converted to a number with float(..).. But in an ideal world we just want to pass the number right away instead of creating the intermediate string.

What we would want is to do something like

CONTAINER_CONNECTION_TIMEOUT = float(os.environ.get("SAM_CLI_CONTAINER_CONNECTION_TIMEOUT")) if "SAM_CLI_CONTAINER_CONNECTION_TIMEOUT" in os.environ else 20

(check if the envvar exists, and only in that case convert to float, otherwise pass the number directly)

but that's terrible code too, so we can just keep it with what you did here.

@vicheey
Copy link
Copy Markdown
Contributor

vicheey commented Apr 9, 2025

Address in this #7947

@vicheey vicheey closed this Apr 10, 2025
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