Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically expose cogs as globals in python eval #71

Closed
silasary opened this issue Sep 11, 2020 · 3 comments
Closed

Automatically expose cogs as globals in python eval #71

silasary opened this issue Sep 11, 2020 · 3 comments
Labels
feature request a feature requested for implementation in the jishaku module or cog

Comments

@silasary
Copy link

The Problem

Almost every time I invoke jsk py, it starts with _bot.get_cog('MyCog'). It would be nice if this was exposed as _MyCog.

The Ideal Solution

Iterate over Bot.__cogs and expose them while generating the scope

The Current Solution

Turn on Retain Variables, and manually store cogs in the global context, or manually execute the search every time you eval something.

@ioistired
Copy link
Contributor

ioistired commented Sep 12, 2020

_bot.cogs['MyCog'] is a bit quicker to type. combine that with setting jishaku retain on by default using environment variables and it's not so bad. This also gets into the sticky issue of maintaining that state whenever a cog is reloaded. Potentially that could be solved by passing a custom globals dictionary type to exec that falls back to looking up bot.cogs.

@scarletcafe
Copy link
Owner

I don't really like having this be done by the repl context preparation because it would mean people who use JISHAKU_NO_UNDERSCORE would end up having all their cogs in scope randomly, and since I've seen a decent number of people call their cogs things like Fun and Games I can forsee scoping issues. It would actually be pretty funny to see people be bitten by this, since it would mean people would stop asking me why I prefix the underscore by default.

A potential compromise might be to just add _cogs as an automatic variable, but even that might cause scoping issues (I know many people, including myself, who put their cogs into a cogs.whatever module).

I don't really like the idea of a global fallback dictionary because it means people unfamiliar with the behavior won't know why they have magic ephemeral variables flying around. It's easy to tell that _bot.cogs['Utils'].something() won't work for you if you don't have such a cog, but _Utils.something() is more confusing at a glance.

@scarletcafe scarletcafe added the feature request a feature requested for implementation in the jishaku module or cog label Jan 17, 2021
@scarletcafe
Copy link
Owner

I think I'm ultimately deciding to not do this one. You can trivially use _bot.get_cog to get this behavior with not really that much brevity loss, and without the expense of having potentially conflicting or confusing automatic names in scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request a feature requested for implementation in the jishaku module or cog
Projects
None yet
Development

No branches or pull requests

3 participants