Skip to content

Commit dc603dc

Browse files
style: autofix "ALL" ruff rules + S110 (#671)
Co-authored-by: arielle <[email protected]>
1 parent 38551d1 commit dc603dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+163
-191
lines changed

monty/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
log = logging.getLogger(__name__)
1818

1919
try:
20-
import uvloop # noqa: F401 # pyright: ignore[reportMissingImports]
20+
import uvloop # pyright: ignore[reportMissingImports]
2121

2222
uvloop.install()
2323
log.info("Using uvloop as event loop.")

monty/aiohttp_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def _request(
8080
) -> aiohttp.ClientResponse:
8181
"""Do the same thing as aiohttp does, but always cache the response."""
8282
method = method.upper().strip()
83-
cache_key = f"{method}:{str(str_or_url)}"
83+
cache_key = f"{method}:{str_or_url!s}"
8484
async with self.cache.lock(cache_key):
8585
cached = await self.cache.get(cache_key)
8686
if cached and use_cache:

monty/bot.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Monty(commands.Bot):
5050

5151
name = constants.Client.name
5252

53-
def __init__(self, redis_session: redis.asyncio.Redis, proxy: str = None, **kwargs) -> None:
53+
def __init__(self, redis_session: redis.asyncio.Redis, proxy: str | None = None, **kwargs) -> None:
5454
if TEST_GUILDS:
5555
kwargs["test_guilds"] = TEST_GUILDS
5656
log.warning("registering as test_guilds")
@@ -87,7 +87,7 @@ def db(self) -> async_sessionmaker[AsyncSession]:
8787
"""Alias of `bot.db_session`."""
8888
return self.db_session
8989

90-
def create_http_session(self, proxy: str = None) -> None:
90+
def create_http_session(self, proxy: str | None = None) -> None:
9191
"""Create the bot's aiohttp session."""
9292
self.http_session = CachingClientSession(proxy=proxy)
9393

@@ -163,17 +163,16 @@ async def _create_features(self) -> None:
163163
"""Update the database with all features defined immediately upon launch. No more lazy creation."""
164164
await self.wait_until_first_connect()
165165

166-
async with self._feature_db_lock:
167-
async with self.db.begin() as session:
168-
stmt = sa.select(Feature).options(selectinload(Feature.rollout))
169-
result = await session.scalars(stmt)
170-
existing_feature_names = {feature.name for feature in result.all()}
171-
for feature_enum in constants.Feature:
172-
if feature_enum.value in existing_feature_names:
173-
continue
174-
feature_instance = Feature(feature_enum.value)
175-
session.add(feature_instance)
176-
await session.commit() # this will error out if it cannot be made
166+
async with self._feature_db_lock, self.db.begin() as session:
167+
stmt = sa.select(Feature).options(selectinload(Feature.rollout))
168+
result = await session.scalars(stmt)
169+
existing_feature_names = {feature.name for feature in result.all()}
170+
for feature_enum in constants.Feature:
171+
if feature_enum.value in existing_feature_names:
172+
continue
173+
feature_instance = Feature(feature_enum.value)
174+
session.add(feature_instance)
175+
await session.commit() # this will error out if it cannot be made
177176

178177
await self.refresh_features()
179178

@@ -228,9 +227,8 @@ async def guild_has_feature(
228227
self.features[feature] = feature_instance
229228
# we're defaulting to non-existing features as None, rather than False.
230229
# this might change later.
231-
if include_feature_status and feature_instance:
232-
if feature_instance.enabled is not None:
233-
return feature_instance.enabled
230+
if include_feature_status and feature_instance and feature_instance.enabled is not None:
231+
return feature_instance.enabled
234232

235233
# the feature's enabled status is None, so we should check the guild
236234
# support the guild being None to make it easier to use
@@ -353,7 +351,7 @@ def remove_command(self, name: str) -> commands.Command | None:
353351
command = super().remove_command(name)
354352
if command is None:
355353
# Even if it's a root alias, there's no way to get the Bot instance to remove the alias.
356-
return
354+
return None
357355

358356
self.dispatch("command_remove", command)
359357
self._remove_root_aliases(command)

monty/config/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66

77
__all__ = (
8-
"METADATA",
9-
"GROUP_TO_ATTR",
108
"CATEGORY_TO_ATTR",
9+
"GROUP_TO_ATTR",
10+
"METADATA",
1111
"Category",
1212
"ConfigAttrMetadata",
13-
"SelectGroup",
1413
"FreeResponseMetadata",
14+
"SelectGroup",
1515
"SelectOptionMetadata",
1616
"get_category_choices",
1717
)

monty/config/_validate_metadata.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ def _check_config_metadata(metadata: dict[str, ConfigAttrMetadata]) -> None:
1313
assert isinstance(m.select_option, SelectOptionMetadata)
1414
assert m.type is bool
1515
if m.modal:
16-
assert m.description and len(m.description) <= 45
16+
assert m.description
17+
assert len(m.description) <= 45
1718
if m.depends_on_features:
1819
for feature in m.depends_on_features:
1920
assert feature in constants.Feature
2021
for c in Category:
2122
if not any(c in m.categories for m in metadata.values()):
22-
raise ValueError(f"Category {c} has no associated config attributes")
23+
msg = f"Category {c} has no associated config attributes"
24+
raise ValueError(msg)

monty/config/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010

1111
__all__ = (
12-
"METADATA",
1312
"CATEGORY_TO_ATTR",
1413
"GROUP_TO_ATTR",
14+
"METADATA",
1515
)
1616

1717

monty/constants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Client:
8383

8484
class Database:
8585
postgres_bind: str = environ.get("DB_BIND", "")
86-
run_migrations: bool = not (environ.get("DB_RUN_MIGRATIONS", "true").lower() == "false")
86+
run_migrations: bool = environ.get("DB_RUN_MIGRATIONS", "true").lower() != "false"
8787
migration_target: str = environ.get("DB_MIGRATION_TARGET", "head")
8888

8989

@@ -97,7 +97,7 @@ class Monitoring:
9797
debug_logging = environ.get("LOG_DEBUG", "true").lower() == "true"
9898
sentry_enabled = bool(environ.get("SENTRY_DSN"))
9999
trace_loggers = environ.get("BOT_TRACE_LOGGERS")
100-
log_mode: Literal["daily", "dev"] = "daily" if "daily" == environ.get("BOT_LOG_MODE", "dev").lower() else "dev"
100+
log_mode: Literal["daily", "dev"] = "daily" if environ.get("BOT_LOG_MODE", "dev").lower() == "daily" else "dev"
101101

102102
public_status_page: str | None = environ.get("UPTIME_STATUS_PAGE") or None
103103
ping_url: str = environ.get("UPTIME_URL", "")
@@ -207,7 +207,7 @@ class Icons:
207207
"%3Fv%3D1/https/cdn.discordapp.com/emojis/654080405988966419.png?width=20&height=20"
208208
)
209209
github_avatar_url = "https://avatars1.githubusercontent.com/u/9919"
210-
python_discourse = "https://global.discourse-cdn.com/business6/uploads/python1/optimized/1X/4c06143de7870c35963b818b15b395092a434991_2_180x180.png" # noqa: E501
210+
python_discourse = "https://global.discourse-cdn.com/business6/uploads/python1/optimized/1X/4c06143de7870c35963b818b15b395092a434991_2_180x180.png"
211211

212212

213213
## Authentication and Endpoint management for external services

monty/database/feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ class Feature(MappedAsDataclass, Base):
2626
def validate_name(self, key: str, name: str) -> str:
2727
"""Validate the `name` attribute meets the regex requirement."""
2828
if not NAME_REGEX.fullmatch(name):
29-
err = f"The provided feature name '{name}' does not match the name regex {str(NAME_REGEX)}"
29+
err = f"The provided feature name '{name}' does not match the name regex {NAME_REGEX!s}"
3030
raise ValueError(err)
3131
return name

monty/database/guild.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Guild(Base):
1111
__tablename__ = "guilds"
1212

1313
id: Mapped[int] = mapped_column(sa.BigInteger, primary_key=True, autoincrement=False)
14-
# todo: this should be a many to many relationship
14+
# TODO: this should be a many to many relationship
1515
feature_ids: Mapped[list[str]] = mapped_column(
1616
MutableList.as_mutable(sa.ARRAY(sa.String(length=50))),
1717
name="features",

monty/database/package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ def base_url(self, value: str | None) -> None:
5555
def validate_name(self, key: str, name: str) -> str:
5656
"""Validate all names are of the format of valid python package names."""
5757
if not NAME_REGEX.fullmatch(name):
58-
err = f"The provided package name '{name}' does not match the name regex {str(NAME_REGEX)}"
58+
err = f"The provided package name '{name}' does not match the name regex {NAME_REGEX!s}"
5959
raise ValueError(err)
6060
return name

0 commit comments

Comments
 (0)