Skip to content

[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
JennyPng:fix/azure-ai-language-questionanswering-authoring-mypy
Closed

[azure-ai-language-questionanswering-authoring] Fix mypy 1.20.1 errors in model_base.py#46453
JennyPng wants to merge 19 commits intoAzure:mainfrom
JennyPng:fix/azure-ai-language-questionanswering-authoring-mypy

Conversation

@JennyPng
Copy link
Copy Markdown
Member

Description

Fixes mypy 1.20.1 errors in azure-ai-language-questionanswering-authoring.

Closes #46122

Root Cause

In model_base.py, _attr_to_rest_field and _backcompat_attr_to_rest_field were assigned on cls inside __new__ with inline type annotations (e.g. cls._attr_to_rest_field: dict[str, _RestField] = ...). Mypy 1.20.1 now correctly flags this as Cannot access instance-only attribute on class object [misc] because inline annotations on class attributes accessed via cls inside __new__ are treated as instance-only.

Fix

Declared _attr_to_rest_field and _backcompat_attr_to_rest_field as typing.ClassVar in the Model class body and removed the inline type annotations from the assignments inside __new__.

Verification

next-mypy check completed with exit code 0

Copilot AI and others added 19 commits March 19, 2026 21:09
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azure-ai-language-questionanswering-authoring needs typing updates for mypy version 1.20.1

2 participants