microsoft / pyright

Static Type Checker for Python
Other
13.28k stars 1.44k forks source link

[verifytypes] Possible regression when analysing a generic class with a type attached leading to unknown types #5612

Closed davfsa closed 1 year ago

davfsa commented 1 year ago

Describe the bug

When updating to pyright 1.1.318 from 1.1.317, our verify-types started failing when resolving the type of some generic classes with concrete types attached to them, leading to unknown types in the signature.

Reproduction steps

Unfortunately I have not been able to find a small reproducer of the error outside of our codebase. You can find the logs for the GitHub run here https://github.com/hikari-py/hikari/actions/runs/5622755205/job/15236000206?pr=1666#step:7:126.

Full logs ``` nox > Running session verify-types nox > Creating virtual environment (virtualenv) using python in .nox/verify-types nox > python -m pip install . -r dev-requirements/pyright.txt nox > pyright --verifytypes hikari --ignoreexternal added 1 package, and audited 2 packages in 2s found 0 vulnerabilities Module name: "hikari" Package directory: "/home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari" Module directory: "/home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari" Path of py.typed file: "/home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/py.typed" Public modules: 98 hikari hikari.__main__ hikari.api hikari.api.cache hikari.api.config hikari.api.entity_factory hikari.api.event_factory hikari.api.event_manager hikari.api.interaction_server hikari.api.rest hikari.api.shard hikari.api.special_endpoints hikari.api.voice hikari.applications hikari.audit_logs hikari.channels hikari.cli hikari.colors hikari.colours hikari.commands hikari.components hikari.embeds hikari.emojis hikari.errors hikari.events hikari.events.application_events hikari.events.base_events hikari.events.channel_events hikari.events.guild_events hikari.events.interaction_events hikari.events.lifetime_events hikari.events.member_events hikari.events.message_events hikari.events.reaction_events hikari.events.role_events hikari.events.scheduled_events hikari.events.shard_events hikari.events.typing_events hikari.events.user_events hikari.events.voice_events hikari.files hikari.guilds hikari.impl hikari.impl.buckets hikari.impl.cache hikari.impl.config hikari.impl.entity_factory hikari.impl.event_factory hikari.impl.event_manager hikari.impl.event_manager_base hikari.impl.gateway_bot hikari.impl.interaction_server hikari.impl.rate_limits hikari.impl.rest hikari.impl.rest_bot hikari.impl.shard hikari.impl.special_endpoints hikari.impl.voice hikari.intents hikari.interactions hikari.interactions.base_interactions hikari.interactions.command_interactions hikari.interactions.component_interactions hikari.interactions.modal_interactions hikari.internal hikari.internal.aio hikari.internal.attrs_extensions hikari.internal.cache hikari.internal.collections hikari.internal.data_binding hikari.internal.deprecation hikari.internal.enums hikari.internal.fast_protocol hikari.internal.mentions hikari.internal.net hikari.internal.reflect hikari.internal.routes hikari.internal.signals hikari.internal.spel hikari.internal.time hikari.internal.ux hikari.invites hikari.iterators hikari.locales hikari.messages hikari.permissions hikari.presences hikari.scheduled_events hikari.sessions hikari.snowflakes hikari.stickers hikari.templates hikari.traits hikari.undefined hikari.urls hikari.users hikari.voices hikari.webhooks Symbols used in public interface: hikari.ExceptionEvent /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/events/base_events.py:55:57 - error: Type argument 1 for class "ExceptionEvent" has unknown type hikari.events.ExceptionEvent /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/events/base_events.py:6:57 - error: Type argument 1 for class "ExceptionEvent" has unknown type hikari.internal.cache.GuildRecord.members /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:232:5 - error: Type argument 2 for class "ExtendedMutableMapping" has partially unknown type Type is RefCell[Unknown] hikari.internal.cache.InviteData.inviter /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:340:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.InviteData.target_user /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:342:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.InviteData.build_from_entity /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:373:9 - error: Type of parameter "inviter" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:373:9 - error: Type of parameter "target_user" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.MemberData.user /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:408:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.MemberData.build_from_entity /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:423:9 - error: Type of parameter "user" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.KnownCustomEmojiData.user /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:467:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.KnownCustomEmojiData.build_from_entity /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:473:9 - error: Type of parameter "user" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.GuildStickerData.user /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:519:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.GuildStickerData.build_from_entity /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:522:9 - error: Type of parameter "user" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.RichActivityData.emoji /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:565:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.RichActivityData.build_from_entity /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:574:9 - error: Type of parameter "emoji" is partially unknown Parameter type is "RefCell[Unknown] | str | None" Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.MessageInteractionData.user /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:677:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.MessageInteractionData.build_from_entity /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:680:9 - error: Type of parameter "user" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.MessageData.author /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:717:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.MessageData.member /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:718:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.MessageData.user_mentions /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:890:18 - error: Type argument 1 for type alias "UndefinedOr" has partially unknown type /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:890:18 - error: Type argument 2 for class "Mapping" has partially unknown type Type is RefCell[Unknown] hikari.internal.cache.MessageData.referenced_message /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:741:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.MessageData.build_from_entity /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:747:9 - error: Type of parameter "author" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:747:9 - error: Type of parameter "member" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:747:9 - error: Type of parameter "user_mentions" is partially unknown Parameter type is "UndefinedOr[Mapping[Snowflake, RefCell[Unknown]]]" Type argument 1 for type alias "UndefinedOr" has partially unknown type Type argument 2 for class "Mapping" has partially unknown type /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:747:9 - error: Type of parameter "referenced_message" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:747:9 - error: Type of parameter "interaction_user" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.MessageData.update /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:860:9 - error: Type of parameter "user_mentions" is partially unknown Parameter type is "UndefinedOr[Mapping[Snowflake, RefCell[Unknown]]]" Type argument 1 for type alias "UndefinedOr" has partially unknown type Type argument 2 for class "Mapping" has partially unknown type hikari.internal.cache.VoiceStateData.member /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:918:5 - error: Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.VoiceStateData.build_from_entity /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:942:9 - error: Type of parameter "member" is partially unknown Parameter type is "RefCell[Unknown] | None" Type argument 1 for class "RefCell" has unknown type hikari.internal.cache.unwrap_ref_cell /home/runner/work/hikari/hikari/.nox/verify-types/lib/python3.8/site-packages/hikari/internal/cache.py:1004:5 - error: Type of parameter "cell" is partially unknown Parameter type is "RefCell[Unknown]" Type argument 1 for class "RefCell" has unknown type Symbols exported by "hikari": 7083 With known type: 7048 With ambiguous type: 0 With unknown type: 35 (Ignoring unknown types imported from other packages) Functions without docstring: 822 Functions without default param: 0 Classes without docstring: 3 Other symbols referenced but not exported by "hikari": 54 With known type: 54 With ambiguous type: 0 With unknown type: 0 Type completeness score: 99.5% Completed in 9.248sec nox > Command pyright --verifytypes hikari --ignoreexternal failed with exit code 1 nox > Session verify-types failed. ```

Also note, in the logs the first two errors lead to bogus lines. I am not 100% sure it is the same bug as the rest. If its not, I'll open another issue

I have spent some time looking for a reproduction of the issue but have been successful thus far. I will keep trying and update this issue with it when I find it. I am opening this issue in this state with the hope that maybe more eyes would help, and I hope its not too much of an inconvenience :)

Environment information

$ python -m pyright --version
pyright 1.1.318

$ python --version
Python 3.9.11
erictraut commented 1 year ago

Thanks for reporting the issue. This was caused by a recent regression described here. It will be fixed in this week's release (1.1.320).

davfsa commented 1 year ago

Thanks for the quick reply!

Sorry for not finding the issue, I had a look but completely skipped over the details of that one

erictraut commented 1 year ago

No worries. It wasn't at all obvious that the issues were related.

erictraut commented 1 year ago

This is addressed in pyright 1.1.320, which I just published. It will also be included in a future version of pylance.