mypy checks violation in AzureBlobStorage #7979

Closed
opened 2026-02-21 18:23:21 -05:00 by yindo · 1 comment
Owner

Originally created by @bowenliang123 on GitHub (Feb 5, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

master

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  • the violation in mypy checks:
extensions/storage/azure_blob_storage.py:25: error: Incompatible types in assignment (expression has type "None", variable has type "DefaultAzureCredential")  [assignment]
extensions/storage/azure_blob_storage.py:67: error: Argument "account_url" to "BlobServiceClient" has incompatible type "str | None"; expected "str"  [arg-type]
Found 2 errors in 1 file (checked 952 source files)

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @bowenliang123 on GitHub (Feb 5, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version master ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce - the violation in mypy checks: ``` extensions/storage/azure_blob_storage.py:25: error: Incompatible types in assignment (expression has type "None", variable has type "DefaultAzureCredential") [assignment] extensions/storage/azure_blob_storage.py:67: error: Argument "account_url" to "BlobServiceClient" has incompatible type "str | None"; expected "str" [arg-type] Found 2 errors in 1 file (checked 952 source files) ``` ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:23:21 -05:00
yindo closed this issue 2026-02-21 18:23:21 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 5, 2025):

The mypy errors you're encountering in the azure_blob_storage.py file are related to type mismatches. Here's how you can address them:

  1. Incompatible types in assignment (line 25):
    The error indicates that None is being assigned to a variable expected to be of type DefaultAzureCredential. To resolve this, ensure that self.credential is always assigned a DefaultAzureCredential or handle the None case appropriately. You might need to adjust the type hint for self.credential to allow None if it's a valid state, like this:

    from typing import Optional
    from azure.identity import DefaultAzureCredential
    
    self.credential: Optional[DefaultAzureCredential] = None
    
  2. Incompatible type for account_url (line 67):
    The error suggests that account_url is expected to be a string, but it might be None. Ensure that dify_config.AZURE_BLOB_ACCOUNT_URL is always a string. If it can be None, you should handle this case before passing it to BlobServiceClient. For example:

    if self.account_url is not None:
        self.blob_service_client = BlobServiceClient(account_url=self.account_url, credential=self.credential)
    else:
        # Handle the None case appropriately
    

By ensuring that the types match the expected types, you should be able to resolve these mypy errors.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Feb 5, 2025): <!-- Answer --> The mypy errors you're encountering in the `azure_blob_storage.py` file are related to type mismatches. Here's how you can address them: 1. **Incompatible types in assignment (line 25):** The error indicates that `None` is being assigned to a variable expected to be of type `DefaultAzureCredential`. To resolve this, ensure that `self.credential` is always assigned a `DefaultAzureCredential` or handle the `None` case appropriately. You might need to adjust the type hint for `self.credential` to allow `None` if it's a valid state, like this: ```python from typing import Optional from azure.identity import DefaultAzureCredential self.credential: Optional[DefaultAzureCredential] = None ``` 2. **Incompatible type for `account_url` (line 67):** The error suggests that `account_url` is expected to be a string, but it might be `None`. Ensure that `dify_config.AZURE_BLOB_ACCOUNT_URL` is always a string. If it can be `None`, you should handle this case before passing it to `BlobServiceClient`. For example: ```python if self.account_url is not None: self.blob_service_client = BlobServiceClient(account_url=self.account_url, credential=self.credential) else: # Handle the None case appropriately ``` By ensuring that the types match the expected types, you should be able to resolve these mypy errors. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/44bf563f-f3e5-4251-b5c1-0ae1fd280868?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/44bf563f-f3e5-4251-b5c1-0ae1fd280868?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/44bf563f-f3e5-4251-b5c1-0ae1fd280868?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/44bf563f-f3e5-4251-b5c1-0ae1fd280868?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/44bf563f-f3e5-4251-b5c1-0ae1fd280868?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/44bf563f-f3e5-4251-b5c1-0ae1fd280868?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7979