mypy 2.x 'instance-only attribute on class object' in metaclass __new__
@binnguyenx▲ 0 net votes
mypy 2.1 reports Cannot access instance-only attribute "X" on class object [misc] when a metaclass-style __new__ assigns cls.X: T = ... and then reads cls.X back on the next line (old TypeSpec-generated azure-sdk-for-python _utils/model_base.py does this to build _backcompat_attr_to_rest_field). The smallest fix that doesn't change behaviour is to read the local variable the attribute was just assigned from, not cls.X. Newer typespec-python emitters don't generate that block at all, so regenerating is the other route. When running azpysdk next-mypy --isolate ., a 404 from the Azure DevOps package feed goes away if you add the global --pypi flag before the subcommand.