Code Quality changes #2980
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2980
Loading…
Reference in a new issue
No description provided.
Delete branch "codehealth"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Description of the changes
It was easier making a new PR than reverting changes ...
This is a variant of #2978 but it doesn't have the PyCharm inspections hints, and it doesn't break l18n 👀
This one also catches a few typos and mispelling that the original did not.
This PR essentially organises imports alphabetically into 3 groups.
Built-ins
3rd Party
Package
It also removes unused variables, convert lamda assignment to def's to PEP8 stops complaining and some other minor tweaks
For other people coming across some of this later, as some discussion has happened in discord.
We should avoid using
_as a placeholder var name anywhere in red's codebase due to interactions with gettext and i18n use.It's fine to rename something to
_loop_counteror something else which indicates to tools that the var name isn't important.Some of these changes aren't ready to go.
I'm still mixed on accepting the import sorting without also making it a requirement going forward.
Doing this as is just increases the size of diffs every so often as we resort.
There's a lot of whitespace changes here which don't seem like positives.
Still seems like too much of this is being done to satisfy tools we haven't and probably won't standardize on.
Why?
why? (and also, dont use
\line continuations here)This adds an unneeded overhead to each case of it. Better to fix the typhehint on
ctx.sendsee #2520 for more details on things needed around this.Why is this PR adjusting whitespace in comments outside of a line-length goal?
@ -360,9 +359,8 @@ class Warnings(commands.Cog):warning(_("You are not allowed to check warnings for other users!")))No. This should be changed to use
hasattrrather than try/except if we aren't usinguseridbelowWhy?
\*down in the docstring below is an invalid escape character, and is technically deprecated since Python 3.6. Sometimes people escape**kwargsin docstrings with\*\*kwargs(same thing with*args->\*args), thinking that sphinx will start bold/emphasis formatting. But sphinx actually handles this, and suggests omitting the backslashes for varargs: https://www.sphinx-doc.org/en/master/usage/extensions/example_numpy.htmlSo, TL;DR, don't use
r"""docstrings containing\*\*kwargs, use plain unicode"""docstrings containing**kwargs.This is due to line length being longer than 99 characters, one bellow it’s the same but the backlash bellow is so that when this its printed to a user it isn’t forced into a new line
My "why" was more, why not fix the root issue here, just not expressing it as such.
Didn't notice the line length on this one was that long, mildly surprised black didn't complain about it before given that it was already inside parens.
Same here like length was longer than 99, for some reason black didn’t complain for some of these but IDE flagged them as being too long (usually 100/110 characters
Yeah, this'll get rendered like this in the help command:
I always get slightly annoyed with how docstrings end up looking in the help command - sticking to the 99-char line length but also considering where the line breaks will appear in the help embed is frustrating.
My solution would be to rewrap/unwrap each paragraph in the help formatter. Code-block help formatter should rewrap, whilst embed help formatter should unwrap. This means a single newline would usually treated as a space (we can make exceptions, possibly for numbered/unordered lists) and double newlines are preserved. Still not sure about this though.
Let's keep the docstring free of line continuations here.
I'll open an issue + handle this case for 3.2 in how we handle help.
Just for clarity, this should be fully up to date with the review from Sinbad and Toby.
I'm noticing some added
# isort: ignorestatements here.For this to be included like this, if we're going to sort imports, it really should be added to both the makefile recipe (for reformatting) and the style test. Otherwise, these comments have no place in our code base.
I've already stated my dislike of mixing isort usage with black in discord, but if you have a set of settings and automatable steps which will produce consistent results, that shouldn't be a blocker to this.
I am going to insist that this be automated to keep the diff sizes down rather than something that just gets changed every so often.
ermm ... this was unintentional ... i missed that the isort stuff was on this branch, let me remove them for now, there's 1 PR pending on the isort repo that after it's merged we should be able to fully automate to where black and isort can be used together consistently
Okay so Implemented both iSort and Black into tests, this is using iSort settings reccomended by the official Black docs.
All test are passing and no compatibility issues.
I would say if we want go ahead and use iSort in the project for further formatting consistency this PR is ready and could be merged after 3.2 (to reduce the number of conflicts just priort to a major release)
Lets not change deployment versions... they are currently working on black magic and I don't want anything breaking with them.
Same over here.
Same over here.
Same over here.
WUT ... I though I updated these to 3.7.5 .... sigh
noted i'll ensure its 3.7.5 and py37
oh wait im dumb .... shouldn't at least the TOXENV be py37, since the bot no longer supports python3.6 so running the test agaisnt 3.7 would be more realist and find bugs caused by an specific version of python?
I haven't reviewed this in full. I'm still skeptical of a lot of the changes here at a surface level.
I had a few specific comments, but also I don't think it's appropriate here to be adding
# -*- coding: utf-8 -*-to the top of each python file.This is a python3.7+ project. Every python file is treated as utf-8 by default as of python3.
Encoding specifications are only neccessary when they differe from the expected, It's just noise here and doesn't even draw contrast in any files where we might need a different encoding because all of the files are utf-8.
@ -0,0 +1,15 @@[settings]All of these headings are just visual noise. If isort is being enforced, they don't do anything useful, isort will sort it out anyway.
Adding this pre-commit config like this is a strong No from me. It requires we maintain settings in multiple places. We have configurations for these already, we have tests that will fail if someone didn't comply, and we have an easy way to run anything which should be automated. IDEs will format with black using our settings already just by setting black as the formatting provider. pre-commit runs in an isolated environment each time, ignoring our central settings.
As an example of the trouble this can cause, this has args which mismatch the ones we are using for one of the tools here, and you just created it. The fewer places we duplicate settings, the better.
This just isn't suited to the project.
Are we sure thats the case when I was running the pre-commit hook localy based on this file it was using the settings from the setup.cfg, the individual files and the .ini file
Reason I added here was something user could easily run to process all the formatting in 1 command, and ensure everything will pass the Style check while applying the extra style stuff thats black and isort compatible thats in the pre-commit hooks (like json formatting etc)
@ -0,0 +1,15 @@[settings]So yeah this came up on discord before, yes they are noise but ... it helps people who are less familiar with the ordering prior to running isort. So this is more educational than anything happy to remove but from the discord talks they would be here to explain the ordering so people learn it rather than just having a tools "randomly" sort things priort to commiting.
So this is the case for people with a real IDE, but in the past when using a non python IDE i did hit issues when editing on Windows and handling emojis and the emojis breaking
That's the fault of your IDE and not the project. Visual studio code on Windows has fine emoji support.
make reformatalready handles the style bit. And yes, pre-commit creates a virtualenv specifically for all of this, using the versions specified here, not in setup.cfg and using the args specified here over the ones in our configuration files, which makes this another place we would need to update multiple things rather than just let people be responsible for their own development environments and catch it at the tests.@ -0,0 +1,15 @@[settings]Info like this belongs in contributing.md, not in every source code file. This isn't a critical comment that needs visibility everywhere something is in use.
Marking this is blocked for 2 reasons.
Let's wait on isort 5.0.0, it's supposed to be getting some extra stuff to make it cooperate with black a bit better.
This still appears to be touching files that were generated, not written (localization messages) which I'm sure isn't in our interests to have multiple tools changing.
Pull request closed