Skip to content

Add action flag to eval#677

Closed
Martmists-GH wants to merge 3 commits into
python-discord:masterfrom
Martmists-GH:master
Closed

Add action flag to eval#677
Martmists-GH wants to merge 3 commits into
python-discord:masterfrom
Martmists-GH:master

Conversation

@Martmists-GH
Copy link
Copy Markdown
Contributor

  • Implements Literal (requires 3.7+, implementation by Danny#0007)
  • Hourly job to remove unused contexts

Copy link
Copy Markdown
Contributor

@scragly scragly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation uses an unnecessary imagining for commands processing with this Literal converter that's handling something entirely capable of being handled by commands groups, which are already well used elsewhere in the project.

This PR has also not been linted before being created. This is not the first time you've created a PR that has lacked the basic care that's expected when contributing.

Due to the above considerations, I'm closing the PR until you can correctly setup your environment, linter, pre-commit hook and take into consideration the existing framework and project style, all of which are things mentioned in our contributing guidelines.

Comment thread bot/cogs/snekbox.py
await ctx.invoke(self.bot.get_command("help"), "eval")
return

if action == "-save":
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire thing appears to be a poor-mans subcommand handler. There's no reason to parse distinct flags contrary to the entire commands framework design when we have the ability to add subcommands through usage of a command group object.

Comment thread bot/cogs/snekbox.py
Comment on lines +49 to +51
# Dict[int[user_id],
# Tuple[str[saved_code],
# datetime[last_used]]]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't randomly leave commented out code in your PRs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't commented out code, this is a comment explaining the type used so other people working on this know what it is.

Comment thread bot/cogs/snekbox.py
Comment on lines +202 to +203
async def eval_command(self, ctx: Context, action: Optional[Literal["-save", "-load"]] = None,
*, code: str = None) -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not conform to typical project style. Multiline arguments are dropped after the brackets:

    async def eval_command(
        self, ctx: Context, action: Optional[Literal["-save", "-load"]] = None, *, code: str = None
    ) -> None:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this fprmat violate PEP8?

Copy link
Copy Markdown
Contributor

@scragly scragly Dec 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

The closing brace/bracket/parenthesis on multi-line constructs may either line up under the first non-whitespace character of the last line of list
or it may be lined up under the first character of the line that starts the multi-line construct, as in:

my_list = [
    1, 2, 3,
    4, 5, 6,
]
result = some_function_that_takes_arguments(
    'a', 'b', 'c',
    'd', 'e', 'f',
)

Even if it wasn't specifically allowed, it wouldn't have violated any of it's forbiddens, and in the end PEP8 is a guide and the existing project style is the determining factor.

Comment thread bot/converters.py
Comment on lines +264 to +282
class Literal:
"""
Matches a literal, useful for e.g. flags.
Can be used with Optional.

Implementation by Danny#0007
"""

def __class_getitem__(cls, item):
if not isinstance(item, tuple):
item = (item,)

class LiteralProxy(Converter):
@classmethod
async def convert(cls, ctx, argument):
if argument in item:
return argument
raise BadArgument(f"Expected literal: one of {list(map(repr, self.literals))}")
return LiteralProxy
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary to add at this point in time due to suggesting to change commands processing to the existing command groups format.

Comment thread bot/converters.py
class Literal:
"""
Matches a literal, useful for e.g. flags.
Can be used with Optional.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter: D205 1 blank line required between summary line and description

Comment thread bot/cogs/snekbox.py
self.contexts = {}
self._run = True

async def clean_task():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter: TYP201 Missing return type annotation for public function

Also where's the docstring here.

@scragly scragly closed this Dec 2, 2019
@MarkKoz MarkKoz added a: utility Related to utility commands: (bot, eval, extensions, jams, reminders, snekbox, utils) invalid This doesn't seem right t: enhancement Changes or improvements to existing features labels Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: utility Related to utility commands: (bot, eval, extensions, jams, reminders, snekbox, utils) invalid This doesn't seem right t: enhancement Changes or improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants