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

Assignment in assert statement cause unbounded variable error in python -O #133

Open
juanqiu1 opened this issue Nov 27, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@juanqiu1
Copy link

juanqiu1 commented Nov 27, 2024

What happened?

In cdsapi 0.7.4, its dependency cads-api-client has a faulty statement in file process.py:204. It writes as

    @property
    def _json_dict(self) -> dict[str, Any]:
        assert isinstance(content := self.json, dict)
        return content

However, if -O mode is invoked by Python, optimization will not execute assert line, making variable content undeclared, hence return statement will raise error.

What are the steps to reproduce the bug?

execute script using cdsapi with python -O

Version

0.7.2-0.7.4

Platform (OS and architecture)

OS Independent

Relevant log output

[vscode@d9e105258f04 daily-era5-downloader]$ python -O handler.py 
Downloading files for the following times: ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00']
/opt/conda/lib/python3.12/site-packages/cads_api_client/api_client.py:83: UserWarning: cannot access local variable 'content' where it is not associated with a value
  warnings.warn(str(exc), UserWarning)
Traceback (most recent call last):
  ....... <intentionally hide>.....
  File "/opt/conda/lib/python3.12/site-packages/cads_api_client/legacy_api_client.py", line 169, in retrieve
    submitted = self.client.submit_and_wait_on_results(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/cads_api_client/api_client.py", line 458, in submit_and_wait_on_results
    return self._retrieve_api.submit(collection_id, **request).make_results()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/cads_api_client/processing.py", line 743, in submit
    return self.get_process(collection_id).submit(**request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/cads_api_client/processing.py", line 732, in get_process
    return Process.from_request("get", url, **self._request_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/cads_api_client/processing.py", line 191, in from_request
    self.log_messages()
  File "/opt/conda/lib/python3.12/site-packages/cads_api_client/processing.py", line 215, in log_messages
    if message_str := self._json_dict.get("message"):
                      ^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.12/site-packages/cads_api_client/processing.py", line 207, in _json_dict
    return content
           ^^^^^^^
UnboundLocalError: cannot access local variable 'content' where it is not associated with a value

Accompanying data

No response

Organisation

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant