ITADN

Can access attribute "__args__" for local class "TypeAliasType", but Cannot access attribute "__args__" for imported class "TypeAliasType"

#11484Closedhunterhogan 创建于 2026-06-11
question
H
hunterhogancommented
Type: <b>Bug</b> The local version of the code does not produce diagnostics, but the imported version does. ```python from __future__ import annotations from soundfile import dtype_str from typing import Literal, TypeAlias dtype_str_local: TypeAlias = Literal['float64', 'float32', 'int32', 'int16'] qq = dtype_str_local.__args__ ww = dtype_str.__args__ ``` <details><summary>Cannot access attribute "__args__" for class "TypeAliasType"</summary> <p> ```json [{ "resource": "/C:/apps/hunterHearsPy/ee.py", "owner": "Pylance", "code": { "value": "reportAttributeAccessIssue", "target": { "$mid": 1, "path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportAttributeAccessIssue.md", "scheme": "https", "authority": "github.com" } }, "severity": 8, "message": "Cannot access attribute \"__args__\" for class \"TypeAliasType\"\n  Attribute \"__args__\" is unknown", "source": "Pylance", "startLineNumber": 9, "startColumn": 16, "endLineNumber": 9, "endColumn": 24, "modelVersionId": 34, "origin": "extHost1" }] ``` </p> </details> Which I assume necessarily leads to <details><summary>Type of "__args__" is unknown</summary> <p> ```json [{ "resource": "/C:/apps/hunterHearsPy/ee.py", "owner": "Pylance", "code": { "value": "reportUnknownMemberType", "target": { "$mid": 1, "path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUnknownMemberType.md", "scheme": "https", "authority": "github.com" } }, "severity": 8, "message": "Type of \"__args__\" is unknown", "source": "Pylance", "startLineNumber": 9, "startColumn": 6, "endLineNumber": 9, "endColumn": 24, "modelVersionId": 34, "origin": "extHost1" }] ``` </p> </details> The Python interpreter can see the `__args__` attribute. <details><summary>Details</summary> <p> ```pycon (hunterhearspy) C:\apps\hunterHearsPy>ver Microsoft Windows [Version 10.0.26200.8655] (hunterhearspy) C:\apps\hunterHearsPy>py Python 3.14.5 (tags/v3.14.5:5607950, May 10 2026, 10:43:50) [MSC v.1944 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. Ctrl click to launch VS Code Native REPL >>> from soundfile import dtype_str >>> dtype_str.__dir__() ['__origin__', '__str__', '__or__', '__init_subclass__', '_inst', '__args__', '__ror__', 'copy_with', '__mro_entries__', '__getitem__', '__subclasshook__', '_getitem', '__static_attributes__', '__doc__', '__setattr__', '__le__', '__gt__', '_make_substitution', '__instancecheck__', '__ge__', '_name', '__getattribute__', '__format__', '__class__', '__dir__', '_determine_new_args', '__reduce_ex__', '__weakref__', '__new__', '__ne__', '__repr__', '__subclasscheck__', '__getstate__', '__init__', '__eq__', '__firstlineno__', '__delattr__', '__sizeof__', '__slots__', '__call__', '__getattr__', '__hash__', '__parameters__', '__module__', '__lt__', '__iter__', '__dict__', '__reduce__'] >>> dtype_str.__args__ ('float64', 'float32', 'int32', 'int16') >>> type(dtype_str.__args__) <class 'tuple'> ``` </p> </details> --- Extension version: 2026.2.104 VS Code version: Code - Insiders 1.125.0-insider (d7ce0ce923f97583f7e03f9c17a149b1601090a3, 2026-06-11T13:27:59+10:00) OS version: Windows_NT x64 10.0.26200 Modes: <details> <summary>System Info</summary> |Item|Value| |---|---| |CPUs|AMD Ryzen 7 5700U with Radeon Graphics (16 x 1797)| |GPU Status|2d_canvas: enabled<br>GPU0: VENDOR= 0x1002, DEVICE=0x164c [AMD Radeon(TM) Graphics], DRIVER_VENDOR=AMD, DRIVER_VERSION=31.0.21925.1001 *ACTIVE*<br>GPU1: VENDOR= 0x1414, DEVICE=0x008c [Microsoft Basic Render Driver], DRIVER_VERSION=10.0.26100.8521<br>Machine model name: <br>Machine model version: <br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_graphite: disabled_off<br>trees_in_viz: disabled_off<br>video_decode: enabled<br>video_encode: enabled<br>webgl: enabled<br>webgpu: enabled<br>webnn: disabled_off| |Load (avg)|undefined| |Memory (System)|12.90GB (3.10GB free)| |Process Argv|| |Screen Reader|no| |VM|0%| </details> <!-- generated by issue reporter -->
关闭于 2026-06-11 2 条评论