Skip to content

Unreachable code in shard.py #10144

Open
Open
@GDOlivercoding

Description

@GDOlivercoding

Summary

I found an unreachable error case in discord.shard or shard.py

Reproduction Steps

Hello! I found an unreachable error case in https://github.com/Rapptz/discord.py/blob/master/discord/shard.py#L520-523 this snippet here when i was browsing the library code,

the snippet is as follows:

                   if item.error.code != 1000:
                        raise item.error
                    if item.error.code == 4014:
                        raise PrivilegedIntentsRequired(item.shard.id) from None

as you can see, the second error case is completely unreachable, as in order to reach there .code must be 4014, which it cannot

further more, setting type checker mode to strict will show us this error:

Condition will always evaluate to False since the types "Literal[1000]" and "Literal[4014]" have no overlap

https://github.com/Rapptz/discord.py/blob/master/discord/shard.py#L151-L157
here is an example where it is correctly written

Minimal Reproducible Code

code = 4014
if item.error.code != 1000:
    raise ValueError("generic raise")
if item.error.code == 4014:
    raise ValueError("specific raise")

Expected Results

Unrelated

Actual Results

Unrelated

Intents

Unrelated

System Information

  • Python v3.12.8-final
  • discord.py v2.5.2-final
  • aiohttp v3.9.3
  • system info: Windows 10 10.0.19045

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    unconfirmed bugA bug report that needs triaging

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions