GithubHelp home page GithubHelp logo

Comments (4)

davfsa avatar davfsa commented on August 24, 2024

We run slotscheck on our CI and dont see any issues with that (https://github.com/hikari-py/hikari/actions/runs/3833692249/jobs/6525422008#step:9:1; latest run at the time of writing) and I dont see how it could cause an issue. We could add an option to disable it, as it is more in-line with the rest of the bot structure, I just forgot about it. But would you mind explaining your issue more in detail?

from hikari.

davfsa avatar davfsa commented on August 24, 2024

Random thought on this, could this be caused by the fact that you dont have a run guard in your file?

if __name__ == "__main__:
    ...

Couldnt this issue be solved by just adding that?

from hikari.

yakMM avatar yakMM commented on August 24, 2024

Yes I have a run guard, but not for the bot declaration. The warning is emitted when the bot object is created, not when the application is run.

There is no need in actually creating a bot object in a library, but it's different for an application: having the bot object as a global variable is a quicker approach than dependency injection for example.

Anyways, my use case was just there as an example, I don't want to make a point from it, it could be worked around.

This issue is mostly about "Hey other features can be activated / disabled (banner, update checks), why not this warning?" - and to trace similar requests from other users (if any).

from hikari.

yakMM avatar yakMM commented on August 24, 2024

Regarding using run guards:

Consider the basic example from the README:

import hikari

bot = hikari.GatewayBot(token="...")

@bot.listen()
async def ping(event: hikari.GuildMessageCreateEvent) -> None:
    """If a non-bot user mentions your bot, respond with 'Pong!'."""

    # Do not respond to bots nor webhooks pinging us, only user accounts
    if not event.is_human:
        return

    me = bot.get_me()

    if me.id in event.message.user_mentions_ids:
        await event.message.respond("Pong!")

bot.run()

Type guard would usually be implemented only to cover the bot.run call, else you have to put all the code under the if:

import hikari

bot = hikari.GatewayBot(token="...")

@bot.listen()
async def ping(event: hikari.GuildMessageCreateEvent) -> None:
    """If a non-bot user mentions your bot, respond with 'Pong!'."""

    # Do not respond to bots nor webhooks pinging us, only user accounts
    if not event.is_human:
        return

    me = bot.get_me()

    if me.id in event.message.user_mentions_ids:
        await event.message.respond("Pong!")

if __name__ == "__main__":
    bot.run()

In this example, the warning will be emitted in any runtime evaluation (including a slotscheck run, for example).

Wouldn't it be more appropriate to put the warning in the run call instead of the __init__, at least?

from hikari.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.