[azure-ai-language-questionanswering-authoring] Fix mypy 1.20.1 errors in model_base.py#46453
Closed
JennyPng wants to merge 19 commits intoAzure:mainfrom
Closed
[azure-ai-language-questionanswering-authoring] Fix mypy 1.20.1 errors in model_base.py#46453JennyPng wants to merge 19 commits intoAzure:mainfrom
JennyPng wants to merge 19 commits intoAzure:mainfrom
Conversation
Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
…sdk black --isolate Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com> Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/22ee17a8-675c-4ec2-909e-243f71c9fa35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…l_base.py Declare _attr_to_rest_field and _backcompat_attr_to_rest_field as ClassVar in the Model class body to fix 'Cannot access instance-only attribute on class object [misc]' errors introduced in mypy 1.20.1. Fixes Azure#46122
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes mypy 1.20.1 errors in
azure-ai-language-questionanswering-authoring.Closes #46122
Root Cause
In
model_base.py,_attr_to_rest_fieldand_backcompat_attr_to_rest_fieldwere assigned onclsinside__new__with inline type annotations (e.g.cls._attr_to_rest_field: dict[str, _RestField] = ...). Mypy 1.20.1 now correctly flags this asCannot access instance-only attribute on class object [misc]because inline annotations on class attributes accessed viaclsinside__new__are treated as instance-only.Fix
Declared
_attr_to_rest_fieldand_backcompat_attr_to_rest_fieldastyping.ClassVarin theModelclass body and removed the inline type annotations from the assignments inside__new__.Verification