Skip to content

Commit

Permalink
Merge pull request #276 from praw-dev/update/pre-commit-hooks
Browse files Browse the repository at this point in the history
Update pre-commit hooks
  • Loading branch information
LilSpazJoekp authored Apr 12, 2024
2 parents 7bc8c10 + a971606 commit 5b0113c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
types: [ python ]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
Expand All @@ -42,7 +42,7 @@ repos:
files: ^(.*\.toml)$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
rev: v0.3.5
hooks:
- id: ruff
args: [ --exit-non-zero-on-fix, --fix ]
Expand All @@ -51,7 +51,7 @@ repos:
- repo: https://github.com/psf/black
hooks:
- id: black
rev: 24.1.1
rev: 24.3.0

- repo: https://github.com/LilSpazJoekp/docstrfmt
hooks:
Expand Down
6 changes: 4 additions & 2 deletions asyncpraw/models/reddit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ def __eq__(self, other: Any | str) -> bool:
def __getattr__(self, attribute: str) -> Any:
"""Return the value of ``attribute``."""
if not attribute.startswith("_") and not self._fetched:
msg = "{0!r} object has no attribute {1!r}. {0!r} object has not been fetched, did you forget to execute '.load()'?".format(
self.__class__.__name__, attribute
msg = (
f"{self.__class__.__name__!r} object has no attribute {attribute!r}."
f" {self.__class__.__name__!r} object has not been fetched, did you"
" forget to execute '.load()'?"
)
raise AttributeError(msg)
msg = f"{self.__class__.__name__!r} object has no attribute {attribute!r}"
Expand Down
4 changes: 2 additions & 2 deletions asyncpraw/models/reddit/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Generator
from typing import TYPE_CHECKING, Any, Iterator

from ...const import API_PATH
from ...exceptions import ClientException
Expand Down Expand Up @@ -516,7 +516,7 @@ def __init__(
"include_links": True,
}

def __iter__(self) -> Generator[Any, None, None]:
def __iter__(self) -> Iterator[Any, None, None]:
"""Provide a way to iterate over the posts in this :class:`.Collection`.
Example usage:
Expand Down
3 changes: 2 additions & 1 deletion asyncpraw/models/reddit/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ async def add(
upload_data = {item["name"]: item["value"] for item in upload_lease["fields"]}
upload_url = f"https:{upload_lease['action']}"

with file.open("rb") as image:
# TODO(@LilSpazJoekp): This is a blocking operation. It should be made async.
with file.open("rb") as image: # noqa: ASYNC101
upload_data["file"] = image
response = await self._reddit._core._requestor._http.post(
upload_url, data=upload_data
Expand Down
6 changes: 4 additions & 2 deletions asyncpraw/models/reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,8 @@ async def _upload_image(
self, *, data: dict[str, str | Any], image_path: str
) -> dict[str, Any]:
file = Path(image_path)
with file.open("rb") as image:
# TODO(@LilSpazJoekp): This is a blocking operation. It should be made async.
with file.open("rb") as image: # noqa: ASYNC101
header = image.read(len(JPEG_HEADER))
image.seek(0)
data["img_type"] = "jpg" if header == JPEG_HEADER else "png"
Expand Down Expand Up @@ -1845,7 +1846,8 @@ async def _upload_style_asset(self, *, image_path: str, image_type: str) -> str:
upload_data = {item["name"]: item["value"] for item in upload_lease["fields"]}
upload_url = f"https:{upload_lease['action']}"

with file.open("rb") as image:
# TODO(@LilSpazJoekp): This is a blocking operation. It should be made async.
with file.open("rb") as image: # noqa: ASYNC101
upload_data["file"] = image
response = await self.subreddit._reddit._core._requestor._http.post(
upload_url, data=upload_data
Expand Down
3 changes: 2 additions & 1 deletion asyncpraw/models/reddit/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,8 @@ async def upload_image(self, file_path: str) -> str:
upload_data = {item["name"]: item["value"] for item in upload_lease["fields"]}
upload_url = f"https:{upload_lease['action']}"

with file.open("rb") as image:
# TODO(@LilSpazJoekp): This is a blocking operation. It should be made async.
with file.open("rb") as image: # noqa: ASYNC101
upload_data["file"] = image
response = await self._reddit._core._requestor._http.post(
upload_url, data=upload_data
Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ target-version = "py38"
include = [
"asyncpraw/**/*.py"
]

[tool.ruff.lint]
ignore = [
"A002", # shadowing built-in
"ANN101", # missing type annotation for self in method
Expand All @@ -101,7 +103,9 @@ ignore = [
"N818", # exception name should be named with an Error suffix
"PLR0913", # too many arguments
"PLR2004", # Magic value used in comparison,
"S101" # use of assert
"S101", # use of assert
"TD003", # Missing issue link on the line following this TODO
"FIX002" # Line contains TODO
]
select = [
"A", # flake8-builtins
Expand Down Expand Up @@ -146,12 +150,12 @@ select = [
]
ignore-init-module-imports = true

[tool.ruff.flake8-annotations]
[tool.ruff.lint.flake8-annotations]
allow-star-arg-any = true
mypy-init-return = true
suppress-dummy-args = true
suppress-none-returning = true

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"asyncpraw/models/mod_notes.py" = ["FA100"]

0 comments on commit 5b0113c

Please sign in to comment.