microsoft / pyright

Static Type Checker for Python
Other
13.13k stars 1.4k forks source link

Unable to detect inherited function in highlighting or IntelliSense when using Enum member/nonmember decorators #8366

Closed Jacob-Friedberg closed 2 months ago

Jacob-Friedberg commented 2 months ago

Environment data

Code Snippet

from enum import auto, Enum, nonmember, member
import random as rand

class _Enum_helper(Enum):
    @classmethod
    #print random enum
    def random(cls):
        choice = rand.choice(list(cls))
        print(f"{choice}")

class Test():
    class A(_Enum_helper):
        FOO = auto()
        BAR = auto()

        @nonmember
        class InnerA(_Enum_helper):
            FIZZ = auto()
            BUZZ = auto()
            pass
        @member
        class InnerB(_Enum_helper):
            FUN = auto()
            BAN = auto()
            pass

        class InnerC(_Enum_helper):
            COOL= auto()
            STUFF = auto()
            pass

Test.A.random() # Has highlighting and IntelliSense auto complete.
Test.A.InnerA.random() # No highlighting or IntelliSense from inherited random
Test.A.InnerB.random() # No highlighting or IntelliSense from inherited random
Test.A.InnerC.random() # Has highlighting and IntelliSense auto-complete. acts like @member   

Expected behavior

Inherited functions should show up in highlighting and auto complete when either member/nonmember enum decorator is used. image image

Actual behavior

Inherited functions do not show up in IntelliSense or highlighting when the class contains an enum decorator such as member or nonmember.

image image

I believe the default behavior for classes inside Enums is to become a member of that enum (effectively @member) until python 3.13 according to this deprecation warning: "DeprecationWarning: In 3.13 classes created inside an enum will not become a member. Use the member decorator to keep the current behavior."

The highlighting and IntelliSense work for the undecorated case (not the functionality I need).

Logs

2024-07-05 15:32:44.860 [info] (Client) Pylance async client (2024.6.1) started with python extension (2024.8.1)
2024-07-05 15:32:45.175 [info] [Info  - 3:32:45 PM] (76164) Pylance language server 2024.6.1 (pyright version 1.1.364, commit 0618acc5) starting
2024-07-05 15:32:45.175 [info] [Info  - 3:32:45 PM] (76164) Server root directory: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist
2024-07-05 15:32:45.175 [info] [Info  - 3:32:45 PM] (76164) Starting service instance "bug"
2024-07-05 15:32:45.194 [info] Auto-Indent enabled
2024-07-05 15:32:45.208 [info] Auto-Indent enabled
2024-07-05 15:32:45.208 [info] (76164) No configuration file found.
2024-07-05 15:32:45.209 [info] (76164) No pyproject.toml file found.
2024-07-05 15:32:45.209 [info] [Info  - 3:32:45 PM] (76164) Setting pythonPath for service "bug": "/bin/python3"
2024-07-05 15:32:45.209 [info] [Info  - 3:32:45 PM] (76164) Setting environmentName for service "bug": "3.12.3 (global)"
2024-07-05 15:32:45.230 [info] [Info  - 3:32:45 PM] (76164) Assuming Python version 3.12.3.final.0
2024-07-05 15:32:45.230 [info] (76164) Assuming Python platform Linux
2024-07-05 15:32:45.269 [info] [Info  - 3:32:45 PM] (76164) Search paths for file:///home/jacob/Dev/bug
2024-07-05 15:32:45.269 [info] [Info  - 3:32:45 PM] (76164)   /home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib
2024-07-05 15:32:45.269 [info] [Info  - 3:32:45 PM] (76164)   /home/jacob/Dev/bug
2024-07-05 15:32:45.269 [info] [Info  - 3:32:45 PM] (76164)   /home/jacob/Dev/bug/typings
2024-07-05 15:32:45.270 [info] [Info  - 3:32:45 PM] (76164)   /home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stubs/...
2024-07-05 15:32:45.270 [info] [Info  - 3:32:45 PM] (76164)   /home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/bundled/stubs
2024-07-05 15:32:45.270 [info] [Info  - 3:32:45 PM] (76164)   /usr/lib/python3.12
2024-07-05 15:32:45.270 [info] [Info  - 3:32:45 PM] (76164)   /usr/lib/python3.12/lib-dynload
2024-07-05 15:32:45.270 [info] [Info  - 3:32:45 PM] (76164)   /usr/local/lib/python3.12/dist-packages
2024-07-05 15:32:45.270 [info] [Info  - 3:32:45 PM] (76164)   /usr/lib/python3/dist-packages
2024-07-05 15:32:45.270 [info] [Info  - 3:32:45 PM] (76164) Adding fs watcher for library directories:
 file:///usr/lib/python3.12
file:///usr/lib/python3.12/lib-dynload
file:///usr/local/lib/python3.12/dist-packages
file:///usr/lib/python3/dist-packages
2024-07-05 15:32:45.270 [info] [Info  - 3:32:45 PM] (76164) Adding fs watcher for directories:
 file:///home/jacob/Dev/bug
2024-07-05 15:32:45.270 [info] (76164) Searching for source files
2024-07-05 15:32:45.284 [info] (76164) Found module distro_info : 1.7+build1
2024-07-05 15:32:45.285 [info] (76164) Found module jsonpatch : 1.32
2024-07-05 15:32:45.285 [info] (76164) Found module jsonpointer : 2.0
2024-07-05 15:32:45.286 [info] (76164) Found module netifaces : 0.11.0
2024-07-05 15:32:45.287 [info] (76164) Found module pycurl : 7.45.3
2024-07-05 15:32:45.287 [info] (76164) Found module six : 1.16.0
2024-07-05 15:32:45.288 [info] (76164) Found module typing_extensions : 4.10.0
2024-07-05 15:32:45.291 [info] (76164) Found module attrs : 23.2.0
2024-07-05 15:32:45.291 [info] (76164) Found module automat : 22.10.0
2024-07-05 15:32:45.291 [info] (76164) Found module babel : 2.10.3
2024-07-05 15:32:45.292 [info] (76164) Found module bcrypt : 3.2.2
2024-07-05 15:32:45.292 [info] (76164) Found module blinker : 1.7.0
2024-07-05 15:32:45.293 [info] (76164) Found module certifi : 2023.11.17
2024-07-05 15:32:45.293 [info] (76164) Found module chardet : 5.2.0
2024-07-05 15:32:45.293 [info] (76164) Found module click : 8.1.6
2024-07-05 15:32:45.296 [info] (76164) Found module colorama : 0.4.6
2024-07-05 15:32:45.296 [info] (76164) Found module configobj : 5.0.8
2024-07-05 15:32:45.296 [info] (76164) Found module constantly : 23.10.4
2024-07-05 15:32:45.297 [info] (76164) Found module cryptography : 41.0.7
2024-07-05 15:32:45.298 [info] (76164) Found module dbus : 1.3.2
2024-07-05 15:32:45.298 [info] (76164) Found module distro : 1.9.0
2024-07-05 15:32:45.299 [info] (76164) Found module httplib2 : 0.20.4
2024-07-05 15:32:45.299 [info] (76164) Found module hyperlink : 21.0.0
2024-07-05 15:32:45.299 [info] (76164) Found module idna : 3.6
2024-07-05 15:32:45.300 [info] (76164) Found module incremental : 22.10.0
2024-07-05 15:32:45.300 [info] (76164) Found module jinja2 : 3.1.2
2024-07-05 15:32:45.301 [info] (76164) Found module jsonschema : 4.10.3
2024-07-05 15:32:45.302 [info] (76164) Found module launchpadlib : 1.11.0
2024-07-05 15:32:45.302 [info] (76164) Found module lazr : 0.14.6
2024-07-05 15:32:45.302 [info] (76164) Found module markdown_it : 3.0.0
2024-07-05 15:32:45.303 [info] (76164) Found module markupsafe : 2.1.5
2024-07-05 15:32:45.303 [info] (76164) Found module mdurl : 0.1.2
2024-07-05 15:32:45.304 [info] (76164) Found module oauthlib : 3.2.2
2024-07-05 15:32:45.304 [info] (76164) Found module pyasn1 : 0.4.8
2024-07-05 15:32:45.305 [info] (76164) Found module pygments : 2.17.2
2024-07-05 15:32:45.306 [info] (76164) Found module pyparsing : 3.1.1
2024-07-05 15:32:45.306 [info] (76164) Found module pyrsistent : 0.20.0
2024-07-05 15:32:45.306 [info] (76164) Found module pytz : 2024.1
2024-07-05 15:32:45.307 [info] (76164) Found module requests : 2.31.0
2024-07-05 15:32:45.307 [info] (76164) Found module rich : 13.7.1
2024-07-05 15:32:45.308 [info] (76164) Found module service_identity : 24.1.0
2024-07-05 15:32:45.309 [info] (76164) Found module setuptools : 68.1.2
2024-07-05 15:32:45.309 [info] (76164) Found module systemd : 235
2024-07-05 15:32:45.310 [info] (76164) Found module twisted : 24.3.0
2024-07-05 15:32:45.310 [info] (76164) Found module urllib3 : 2.0.7
2024-07-05 15:32:45.311 [info] (76164) Found module wadllib : 1.3.6
2024-07-05 15:32:45.311 [info] (76164) Found module zope : 6.1
2024-07-05 15:32:45.313 [info] [Info  - 3:32:45 PM] (76164) Found 1 source file
2024-07-05 15:32:45.315 [info] (76164) pytest configurations: {"message":"request cancelled","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-07-05 15:32:45.316 [info] Auto-Indent enabled
2024-07-05 15:32:45.316 [info] (76164) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-07-05 15:32:45.341 [info] (76164) Attempting to resolve using local imports: __builtins__
2024-07-05 15:32:45.348 [info] (76164) [FG] parsing: file:///home/jacob/Dev/bug/bug.py (29ms)
2024-07-05 15:32:45.407 [info] (76164) [FG] parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 1ms] (58ms)
2024-07-05 15:32:45.435 [info] (76164) [FG] binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/builtins.pyi (26ms)
2024-07-05 15:32:45.435 [info] (76164) [FG] binding: file:///home/jacob/Dev/bug/bug.py (1ms)
2024-07-05 15:32:45.506 [info] [Info  - 3:32:45 PM] (76164) Background analysis(1) root directory: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist
2024-07-05 15:32:45.509 [info] [Info  - 3:32:45 PM] (76164) Background analysis(1) started
2024-07-05 15:32:45.565 [info] (76164) Found module distro_info : 1.7+build1
2024-07-05 15:32:45.566 [info] (76164) Found module jsonpatch : 1.32
2024-07-05 15:32:45.566 [info] (76164) Found module jsonpointer : 2.0
2024-07-05 15:32:45.567 [info] (76164) Found module netifaces : 0.11.0
2024-07-05 15:32:45.568 [info] (76164) Found module pycurl : 7.45.3
2024-07-05 15:32:45.568 [info] (76164) Found module six : 1.16.0
2024-07-05 15:32:45.569 [info] (76164) Found module typing_extensions : 4.10.0
2024-07-05 15:32:45.572 [info] (76164) Found module attrs : 23.2.0
2024-07-05 15:32:45.573 [info] (76164) Found module automat : 22.10.0
2024-07-05 15:32:45.573 [info] (76164) Found module babel : 2.10.3
2024-07-05 15:32:45.574 [info] (76164) Found module bcrypt : 3.2.2
2024-07-05 15:32:45.574 [info] (76164) Found module blinker : 1.7.0
2024-07-05 15:32:45.574 [info] (76164) Found module certifi : 2023.11.17
2024-07-05 15:32:45.575 [info] (76164) Found module chardet : 5.2.0
2024-07-05 15:32:45.575 [info] (76164) Found module click : 8.1.6
2024-07-05 15:32:45.576 [info] (76164) Found module colorama : 0.4.6
2024-07-05 15:32:45.577 [info] (76164) Found module configobj : 5.0.8
2024-07-05 15:32:45.577 [info] (76164) Found module constantly : 23.10.4
2024-07-05 15:32:45.578 [info] (76164) Found module cryptography : 41.0.7
2024-07-05 15:32:45.579 [info] (76164) Found module dbus : 1.3.2
2024-07-05 15:32:45.579 [info] (76164) Found module distro : 1.9.0
2024-07-05 15:32:45.580 [info] (76164) Found module httplib2 : 0.20.4
2024-07-05 15:32:45.581 [info] (76164) Found module hyperlink : 21.0.0
2024-07-05 15:32:45.581 [info] (76164) Found module idna : 3.6
2024-07-05 15:32:45.582 [info] (76164) Found module incremental : 22.10.0
2024-07-05 15:32:45.583 [info] (76164) Found module jinja2 : 3.1.2
2024-07-05 15:32:45.583 [info] (76164) Found module jsonschema : 4.10.3
2024-07-05 15:32:45.584 [info] (76164) Found module launchpadlib : 1.11.0
2024-07-05 15:32:45.585 [info] (76164) Found module lazr : 0.14.6
2024-07-05 15:32:45.585 [info] (76164) Found module markdown_it : 3.0.0
2024-07-05 15:32:45.586 [info] (76164) Found module markupsafe : 2.1.5
2024-07-05 15:32:45.586 [info] (76164) Found module mdurl : 0.1.2
2024-07-05 15:32:45.587 [info] (76164) Found module oauthlib : 3.2.2
2024-07-05 15:32:45.588 [info] (76164) Found module pyasn1 : 0.4.8
2024-07-05 15:32:45.589 [info] (76164) Found module pygments : 2.17.2
2024-07-05 15:32:45.589 [info] (76164) Found module pyparsing : 3.1.1
2024-07-05 15:32:45.590 [info] (76164) Found module pyrsistent : 0.20.0
2024-07-05 15:32:45.590 [info] (76164) Found module pytz : 2024.1
2024-07-05 15:32:45.591 [info] (76164) Found module requests : 2.31.0
2024-07-05 15:32:45.591 [info] (76164) Found module rich : 13.7.1
2024-07-05 15:32:45.592 [info] (76164) Found module service_identity : 24.1.0
2024-07-05 15:32:45.593 [info] (76164) Found module setuptools : 68.1.2
2024-07-05 15:32:45.593 [info] (76164) Found module systemd : 235
2024-07-05 15:32:45.593 [info] (76164) Found module twisted : 24.3.0
2024-07-05 15:32:45.594 [info] (76164) Found module urllib3 : 2.0.7
2024-07-05 15:32:45.595 [info] (76164) Found module wadllib : 1.3.6
2024-07-05 15:32:45.595 [info] (76164) Found module zope : 6.1
2024-07-05 15:32:45.607 [info] (76164) pytest configurations: {"message":"request cancelled","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-07-05 15:32:45.638 [info] (76164) Attempting to resolve using local imports: __builtins__
2024-07-05 15:32:45.644 [info] (76164) [BG(1)] analyzing: file:///home/jacob/Dev/bug/bug.py ...
2024-07-05 15:32:45.644 [info] (76164) [BG(1)]   parsing: file:///home/jacob/Dev/bug/bug.py (34ms)
2024-07-05 15:32:45.655 [info] [Info  - 3:32:45 PM] (76164) Indexer background runner(2) root directory: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist (index)
2024-07-05 15:32:45.655 [info] [Info  - 3:32:45 PM] (76164) Indexing(2) started
2024-07-05 15:32:45.719 [info] (76164) [BG(1)]   parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 1ms] (73ms)
2024-07-05 15:32:45.723 [info] (76164) [IDX(2)] scan packages file:///home/jacob/Dev/bug ...
2024-07-05 15:32:45.723 [info] (76164) [IDX(2)]   read stdlib indices (20ms)
2024-07-05 15:32:45.750 [info] (76164) [BG(1)]   binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/builtins.pyi (30ms)
2024-07-05 15:32:45.751 [info] (76164) [BG(1)]   binding: file:///home/jacob/Dev/bug/bug.py (0ms)
2024-07-05 15:32:45.772 [info] (76164) [BG(1)]   checking: file:///home/jacob/Dev/bug/bug.py ...
2024-07-05 15:32:45.772 [info] (76164) [BG(1)]     parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/typing.pyi [fs read 0ms] (14ms)
2024-07-05 15:32:45.785 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/typing.pyi (12ms)
2024-07-05 15:32:45.801 [info] (76164) [BG(1)]     parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/types.pyi [fs read 0ms] (6ms)
2024-07-05 15:32:45.806 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/types.pyi (4ms)
2024-07-05 15:32:45.816 [info] (76164) [BG(1)]     parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 0ms] (4ms)
2024-07-05 15:32:45.820 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (4ms)
2024-07-05 15:32:45.828 [info] (76164) [BG(1)]     parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/abc.pyi [fs read 0ms] (1ms)
2024-07-05 15:32:45.829 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/abc.pyi (1ms)
2024-07-05 15:32:45.871 [info] (76164) [BG(1)]     parsing: file:///usr/lib/python3.12/enum.py [fs read 9ms] (39ms)
2024-07-05 15:32:45.886 [info] (76164) [BG(1)]     binding: file:///usr/lib/python3.12/enum.py (15ms)
2024-07-05 15:32:45.890 [info] (76164) [BG(1)]     parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/enum.pyi [fs read 1ms] (3ms)
2024-07-05 15:32:45.892 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/enum.pyi (2ms)
2024-07-05 15:32:45.897 [info] (76164) [BG(1)]     parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/random.pyi [fs read 0ms] (3ms)
2024-07-05 15:32:45.899 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/random.pyi (2ms)
2024-07-05 15:32:45.916 [info] (76164) [BG(1)]     parsing: file:///usr/lib/python3.12/random.py [fs read 0ms] (17ms)
2024-07-05 15:32:45.916 [info] [Info  - 3:32:45 PM] (76164) Could not import '_sha2' in file '/usr/lib/python3.12/random.py'
2024-07-05 15:32:45.916 [info] [Info  - 3:32:45 PM] (76164)   Looking in stubPath 'file:///home/jacob/Dev/bug/typings'
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve stub package using root path 'file:///home/jacob/Dev/bug/typings'
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve using root path 'file:///home/jacob/Dev/bug/typings'
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)   Looking in root directory of execution environment 'file:///home/jacob/Dev/bug'
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve stub package using root path 'file:///home/jacob/Dev/bug'
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve using root path 'file:///home/jacob/Dev/bug'
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)   Finding python search paths
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)   Executing interpreter: '/bin/python3'
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)   Skipping '/usr/lib/python312.zip' because it is not a valid directory
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)   Received 4 paths from interpreter
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)     file:///usr/lib/python3.12
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)     file:///usr/lib/python3.12/lib-dynload
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)     file:///usr/local/lib/python3.12/dist-packages
2024-07-05 15:32:45.917 [info] [Info  - 3:32:45 PM] (76164)     file:///usr/lib/python3/dist-packages
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Looking in python search path 'file:///usr/lib/python3.12'
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve stub package using root path 'file:///usr/lib/python3.12'
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve using root path 'file:///usr/lib/python3.12'
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Looking in python search path 'file:///usr/lib/python3.12/lib-dynload'
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve stub package using root path 'file:///usr/lib/python3.12/lib-dynload'
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve using root path 'file:///usr/lib/python3.12/lib-dynload'
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Looking in python search path 'file:///usr/local/lib/python3.12/dist-packages'
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve stub package using root path 'file:///usr/local/lib/python3.12/dist-packages'
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve using root path 'file:///usr/local/lib/python3.12/dist-packages'
2024-07-05 15:32:45.918 [info] [Info  - 3:32:45 PM] (76164)   Looking in python search path 'file:///usr/lib/python3/dist-packages'
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve stub package using root path 'file:///usr/lib/python3/dist-packages'
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve using root path 'file:///usr/lib/python3/dist-packages'
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Looking in bundled stubs path 'file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/bundled/stubs'
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve stub package using root path 'file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/bundled/stubs'
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve using root path 'file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/bundled/stubs'
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Looking for typeshed stdlib path
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Looking for typeshed stdlib path
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Attempting to resolve using root path 'file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib'
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Typeshed path not found
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Looking for typeshed third-party path
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Looking for typeshed stubs path
2024-07-05 15:32:45.919 [info] [Info  - 3:32:45 PM] (76164)   Typeshed path not found
2024-07-05 15:32:45.928 [info] (76164) [BG(1)]     binding: file:///usr/lib/python3.12/random.py (7ms)
2024-07-05 15:32:45.930 [info] (76164) [BG(1)]     parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/typing_extensions.pyi [fs read 0ms] (5ms)
2024-07-05 15:32:45.934 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/typing_extensions.pyi (3ms)
2024-07-05 15:32:45.938 [info] (76164) [BG(1)]     parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/collections/abc.pyi [fs read 0ms] (0ms)
2024-07-05 15:32:45.939 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/collections/abc.pyi ...
2024-07-05 15:32:45.939 [info] (76164) [BG(1)]       parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/_collections_abc.pyi [fs read 0ms] (1ms)
2024-07-05 15:32:45.940 [info] (76164) [BG(1)]       binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/_collections_abc.pyi (1ms)
2024-07-05 15:32:45.940 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/collections/abc.pyi (2ms)
2024-07-05 15:32:45.955 [info] (76164) [BG(1)]     parsing: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/_random.pyi [fs read 0ms] (0ms)
2024-07-05 15:32:45.956 [info] (76164) [BG(1)]     binding: file:///home/jacob/.vscode-server/extensions/ms-python.vscode-pylance-2024.6.1/dist/typeshed-fallback/stdlib/_random.pyi (0ms)
2024-07-05 15:32:45.966 [info] (76164) [IDX(2)] scan packages file:///home/jacob/Dev/bug (262ms)
2024-07-05 15:32:45.966 [info] [Info  - 3:32:45 PM] (76164) scanned(2) 73 files over 1 exec env
2024-07-05 15:32:46.023 [info] (76164) [BG(1)]   checking: file:///home/jacob/Dev/bug/bug.py (272ms)
2024-07-05 15:32:46.024 [info] (76164) [BG(1)] analyzing: file:///home/jacob/Dev/bug/bug.py (415ms)
2024-07-05 15:32:46.030 [info] (76164) [BG(1)] SemanticTokens range 0:0 - 35:0 at file:///home/jacob/Dev/bug/bug.py (5ms)
2024-07-05 15:32:46.035 [info] (76164) [BG(1)] SemanticTokens full at file:///home/jacob/Dev/bug/bug.py (2ms)
2024-07-05 15:32:46.123 [info] (76164) [BG(1)] indexing: file:///home/jacob/Dev/bug/bug.py [found 2] (0ms)
2024-07-05 15:32:46.123 [info] (76164) Indexing Done: file:///home/jacob/Dev/bug/bug.py
2024-07-05 15:32:46.124 [info] (76164) pytest configurations: {"message":"script","classes":["Test"],"files":["test_*.py","*_test.py"],"functions":["test"]}
2024-07-05 15:32:46.138 [info] (76164) [IDX(2)] index packages file:///home/jacob/Dev/bug ...
2024-07-05 15:32:46.138 [info] (76164) [IDX(2)]   index execution environment file:///home/jacob/Dev/bug ...
2024-07-05 15:32:46.138 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3.12/__phello__/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.138 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3.12/concurrent/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.138 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3.12/pydoc_data/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.138 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3.12/test/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.138 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3.12/urllib/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.138 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3.12/wsgiref/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.138 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3.12/xmlrpc/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/CommandNotFound/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/DistUpgrade/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/HweSupportStatus/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/UpdateManager/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/aptsources/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/babel/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/cloudinit/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/curl/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/gi/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/janitor/__init__.py [skipped: no '__all__' defined] (1ms)
2024-07-05 15:32:46.139 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/landscape/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.140 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/launchpadlib/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.140 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/pyasn1_modules/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.140 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/softwareproperties/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.140 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/systemd/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.140 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/uaclient/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.140 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/validate/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.140 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/wadllib/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.140 [info] (76164) [IDX(2)]     indexing: file:///usr/lib/python3/dist-packages/zope/__init__.py [skipped: no '__all__' defined] (0ms)
2024-07-05 15:32:46.144 [info] (76164) [IDX(2)]   index execution environment file:///home/jacob/Dev/bug [found 1809 in 47 files] (9ms)
2024-07-05 15:32:46.144 [info] (76164) [IDX(2)] index packages file:///home/jacob/Dev/bug [found 1809 in 1 exec envs] (20ms)
2024-07-05 15:32:46.144 [info] [Info  - 3:32:46 PM] (76164) indexed(2) 47 files over 1 exec env
2024-07-05 15:32:46.176 [info] [Info  - 3:32:46 PM] (76164) Indexing finished(2).
2024-07-05 15:32:46.403 [info] (76164) [BG(1)] SemanticTokens delta previousResultId:1720218766031 at file:///home/jacob/Dev/bug/bug.py (0ms)
Jacob-Friedberg commented 2 months ago

This issue extends to trying to access the enum by name. Does not highlight, does not show in the IntelliSense menu as an auto complete image

erictraut commented 2 months ago

This behavior is due to the way that nonmember and member are defined in the typeshed stubs. Here's the definition of nonmember, for example.

    class nonmember(Generic[_EnumMemberT]):
        value: _EnumMemberT
        def __init__(self, value: _EnumMemberT) -> None: ...

When @nonmember is applied as a decorator to a class definition, it transforms that class into a nonmember object. This object has no method random, so an attempt to access this attribute will be seen as an error by a static type checker.

To fix this, the typeshed definition of nonmember and member would need to be updated. Their constructors should probably return the value they are passed.

    class nonmember:
        def __new__(cls, value: _EnumMemberT) -> _EnumMemberT: ...

Alternatively, a __get__ method could be added:

    class nonmember(Generic[_EnumMemberT]):
        value: _EnumMemberT
        def __init__(self, value: _EnumMemberT) -> None: ...
        def __get__(self, instance: Any, owner: type | None = None, /) -> _EnumMemberT: ...

If you would like to pursue one of these fixes, please file an issue and/or a PR in the typeshed project.

Jacob-Friedberg commented 2 months ago

@erictraut

If you would like to pursue one of these fixes, please file an issue and/or a PR in the typeshed project.

I submitted an issue per your suggestion and the typeshed team has come to a conclusion:

-DaverBall

I'm not sure I agree that this is a typeshed issue, after all nonmember and member at runtime are just simple marker classes, with neither a custom new nor are they descriptors, so lying about that, while not particularly harmful, since they'll be stripped away in classes inheriting from Enum or using the EnumMeta metaclass anyways, it's still inaccurate. It would e.g. hide bugs where they're inappropriately used in other classes.

Enums require special-casing in order to be correctly supported by type checkers, and member/nonmember are part of that special casing, since it can override the default decision of whether or not that attribute is considered a member or not. So I'm not fully convinced it's worth lying about what these marker classes are.

That being said, it might make sense to make these markers generic, simply to give type checkers more flexibility at which point the special-casing is applied, i.e. change them to:


class member(Generic[_EnumMemberT]):
value: _EnumMemberT
def __init__(self, value: _EnumMemberT) -> None: ...

class nonmember(Generic[_EnumMemberT]): value: _EnumMemberT def init(self, value: _EnumMemberT) -> None: ...


> That would allow the special casing to happen at a purely semantic level after type inference, rather than at a syntactic level.

-srittau
>  agree with -Daverball. The typeshed annotations follow the implementation exactly. This requires type checker special casing instead of typeshed hacks, although I'd be fine with making the classes generic, if that helps.

@erictraut 
Im not too familiar with how pylance works internally to be able to answer their question about making the classes generic. Would making those two classes generic allow pylance/enable a feature to be written to pick up the decorated enum/inherited classes?
erictraut commented 2 months ago

Could someone from the pylance team please transfer this issue to pyright? I'd like to think more about it given the feedback from the typeshed maintainers and explore possible solutions.

The "magic" performed by EnumMeta is significant. This requires massive special-casing inside of static type checkers (at best) and makes it impossible or infeasible to statically type check certain enum-related features (at worse). Pyright's support for enum type checking already goes far beyond any other Python static type checker, but there are limits to what can be done.

erictraut commented 2 months ago

This is addressed in pyright 1.1.372.