azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

`SyntaxWarning` while running `az`

Open roy-work opened this issue 1 year ago • 6 comments

Describe the bug

» az storage blob --help
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/blob/_deserialization.py:644: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif num_empty_lines is 2:
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/blob/_deserialization.py:658: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  return marker if marker is not '' else None
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/blob/_serialization.py:189: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if requests is None or len(requests) is 0:
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/blob/_serialization.py:301: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if len(serialized_query) is not 0:
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/blob/_upload_chunking.py:409: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if n is 0 or self._buffer.closed:
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/blob/baseblobservice.py:1082: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if lease_duration is not -1 and \
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/blob/baseblobservice.py:2789: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if lease_duration is not -1 and \
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/common/_connection.py:82: SyntaxWarning: "is" with a literal. Did you mean "=="?
  self.protocol = self.protocol if parsed_url.scheme is '' else parsed_url.scheme
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/blob/blockblobservice.py:608: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while len(data) < count and len(data_chunk) is not 0:
/Users/roy/.azure/cliextensions/storage-preview/azext_storage_preview/vendored_sdks/azure_adls_storage_preview/v2019_02_02_preview/blob/blockblobservice.py:608: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while len(data) < count and len(data_chunk) is not 0:

Group
[the help output follows normally]

Related command

az storage blob --help

Errors

 

Issue script & Debug output

 

Expected behavior

No obvious code quality issues like this.

Environment Summary

» az --version
azure-cli                         2.58.0 *

core                              2.58.0 *
telemetry                          1.1.0

Extensions:
automation                         0.1.1
databricks                         0.8.0
ssh                                2.0.1
storage-preview                    0.8.3

Dependencies:
msal                              1.26.0
azure-mgmt-resource             23.1.0b2

Python location '/usr/local/Cellar/azure-cli/2.58.0/libexec/bin/python'
Extensions directory '/Users/roy/.azure/cliextensions'

Python (Darwin) 3.11.8 (main, Feb  6 2024, 21:21:21) [Clang 15.0.0 (clang-1500.1.0.2.5)]

Legal docs and information: aka.ms/AzureCliLegal


You have 2 update(s) available. Consider updating your CLI installation with 'az upgrade'

(See below: but how can I see what those updates are?)

Additional context

All of these SyntaxWarnings are bugs. Things like is 2 are nonsensical in Python, and if they work, it's through sheer dumb luck (and IB).

I was attempting to determine if there was an update to the storage-preview extension. I cannot find the command for that, if one exists. While running this command,

» az extension update -n storage-preview
Default enabled including preview versions for extension installation now. Disabled in May 2024.

I cannot parse that first sentence at all; grammatically, that seems to just be words.

roy-work avatar Apr 23 '24 22:04 roy-work

Hi @roy-work,

2.58.0 is not the latest Azure CLI(2.59.0).

If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

Hi @roy-work Find similar issue https://github.com/Azure/azure-cli/issues/19112.

Issue title netappfiles: syntax warning
Create time 2021-08-03
Comment number 1

Possible solution: The issue you are facing is related to SyntaxWarning while running az. The SyntaxWarning is caused by nonsensical code like is 2 which is not valid in Python. The existing issue also faced a similar problem with SyntaxWarning. The warnings appeared when packaging azure-cli for Fedora 35 with Python 3.10. The expected behavior is no syntax warnings. The solution to the existing issue was that the problem was in 2.26.1 but appears to be gone in main. You can try updating your CLI installation with 'az upgrade' to see if it resolves the issue.


Please confirm if this resolves your issue.

Thank you for opening this issue, we will look into it.

yonzhan avatar Apr 23 '24 22:04 yonzhan

Hi @roy-work Find similar issue #19112.

Issue title netappfiles: syntax warning Create time 2021-08-03 Comment number 1

Possible solution: The issue you are facing is related to SyntaxWarning while running az. The SyntaxWarning is caused by nonsensical code like is 2 which is not valid in Python. The existing issue also faced a similar problem with SyntaxWarning. The warnings appeared when packaging azure-cli for Fedora 35 with Python 3.10. The expected behavior is no syntax warnings. The solution to the existing issue was that the problem was in 2.26.1 but appears to be gone in main. You can try updating your CLI installation with 'az upgrade' to see if it resolves the issue.

Please confirm if this resolves your issue.

(… good grief, an LLM.)

Same type of error, but different part of the codebase. Different bug.

(I don't think az upgrade would help, as that only affects the base package, and this appears to be coming from an az extension. (It upgrades extensions too, but alas, it didn't tell me which.) I think I need to upgrade the extension. I'll humor the LLM, but … this one takes some time on macOS.

Following this advice was perhaps a mistake; I since realize that these errors are emitted only during Python bytecode compilation; so they're not emitted on subsequent runs. This means that, since I've upgraded, I have no idea if a lack of subsequent warnings is because Python is silencing them, or because an upgrade has fixed them…)

… a sign MS should adopt some static code analysis in their CI pipeline.

roy-work avatar Apr 23 '24 22:04 roy-work

Hi @roy-work , hopefully it was resolved when running az extension update -n storage-preview to update to the latest extension. Thanks.

calvinhzy avatar Apr 24 '24 05:04 calvinhzy

Hi @roy-work , hopefully it was resolved when running az extension update -n storage-preview to update to the latest extension. Thanks.

It would appear the update deleted the extension. The paths in the original error no longer appear to be present.

roy-work avatar May 02 '24 21:05 roy-work