Skip to content

Python 3.12+ type keyword not supported in command types #2951

@Paillat-dev

Description

@Paillat-dev

Summary

type cannot be used to type command types when it should.
Using type is the preferred way to create type aliases in python 3.12+ instead of assigning to a variable directly.

Related:

Reproduction Steps

Test Code
import os
import logging
from typing import reveal_type

import discord
from dotenv import load_dotenv
from discord.ext import bridge

logging.basicConfig(level=logging.INFO)

load_dotenv()

TOKEN = os.getenv("TOKEN_2")

bot = bridge.Bot(intents=discord.Intents.all(), command_prefix="!")


class MyCustomContext(
    bridge.BridgeExtContext
): ...  # I want to do this for whatever reason, doing this *is* supported


type Context = MyCustomContext | bridge.BridgeApplicationContext

reveal_type(Context)

class MyCog(discord.Cog):

    @bridge.bridge_command()
    async def ping(self, ctx: Context, ephemeral: bool = False):
        await ctx.respond(f"Pong! {round(bot.latency * 1000)}ms", ephemeral=ephemeral)

bot.add_cog(MyCog())

bot.run(TOKEN)

Expected Results

The code runs.

Actual Results

The code crashes.

Intents

n/a

System Information

n/a

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions