Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/app-subsc…
Browse files Browse the repository at this point in the history
…riptions
  • Loading branch information
shiftinv committed Oct 19, 2023
2 parents 502e1ad + 913b5c8 commit 0fde8ae
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 42 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
experimental: [false]
fail-fast: false
continue-on-error: ${{ matrix.experimental }}
Expand All @@ -72,7 +72,9 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: pdm install -d -Gspeed -Gdocs -Gvoice
run: |
pdm update --pre aiohttp # XXX: temporarily install aiohttp prerelease for 3.12
pdm install -d -Gspeed -Gdocs -Gvoice
- name: Add .venv/bin to PATH
run: dirname "$(pdm info --python)" >> $GITHUB_PATH
Expand Down Expand Up @@ -129,8 +131,6 @@ jobs:
# run the libcst parsers and check for changes
- name: libcst codemod
env:
LIBCST_PARSER_TYPE: "native"
run: |
nox -s codemod -- run-all
if [ -n "$(git status --porcelain)" ]; then
Expand All @@ -147,7 +147,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: ["windows-latest", "ubuntu-latest", "macos-latest"]
experimental: [false]
fail-fast: true
Expand All @@ -167,11 +167,13 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: pdm install -dG test # needed for coverage
run: |
pdm update --pre aiohttp # XXX: temporarily install aiohttp prerelease for 3.12
pdm install -dG test # needed for coverage
- name: Test package install
run: |
python -m pip install .
python -m pip install --pre . # XXX: temporarily install aiohttp prerelease for 3.12; remove --pre flag again later
- name: Run pytest
id: run_tests
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ repos:
name: "run isort in examples"
files: ^examples/

- repo: https://github.com/psf/black
rev: 23.1.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black
name: "run black in all files"

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.261
rev: v0.0.292
hooks:
- id: ruff
1 change: 1 addition & 0 deletions changelog/1102.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update :meth:`Colour.dark_theme` to match Discord theme change.
1 change: 1 addition & 0 deletions changelog/1102.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add new :class:`Colour`\s: :meth:`~Colour.light_embed` and :meth:`~Colour.dark_embed`.
1 change: 1 addition & 0 deletions changelog/1117.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Start testing with Python 3.12 in CI.
22 changes: 20 additions & 2 deletions disnake/colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ def greyple(cls) -> Self:

@classmethod
def dark_theme(cls) -> Self:
"""A factory method that returns a :class:`Colour` with a value of ``0x36393F``.
"""A factory method that returns a :class:`Colour` with a value of ``0x313338``.
This will appear transparent on Discord's dark theme.
.. versionadded:: 1.5
"""
return cls(0x36393F)
return cls(0x313338)

@classmethod
def fuchsia(cls) -> Self:
Expand All @@ -301,5 +301,23 @@ def yellow(cls) -> Self:
"""
return cls(0xFEE75C)

@classmethod
def light_embed(cls) -> Self:
"""A factory method that returns a :class:`Colour` with a value of ``0xF2F3F5``.
This matches the embed background colour on Discord's light theme.
.. versionadded:: 2.10
"""
return cls(0xF2F3F5)

@classmethod
def dark_embed(cls) -> Self:
"""A factory method that returns a :class:`Colour` with a value of ``0x2B2D31``.
This matches the embed background colour on Discord's dark theme.
.. versionadded:: 2.10
"""
return cls(0x2B2D31)


Color = Colour
6 changes: 3 additions & 3 deletions disnake/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,15 +754,15 @@ def __str__(self) -> str:
# reference: https://discord.com/developers/docs/reference#locales
class Locale(Enum):
bg = "bg"
"Bulgarian | български" # noqa: RUF001
"Bulgarian | български"
cs = "cs"
"Czech | Čeština"
da = "da"
"Danish | Dansk"
de = "de"
"German | Deutsch"
el = "el"
"Greek | Ελληνικά" # noqa: RUF001
"Greek | Ελληνικά"
en_GB = "en-GB"
"English, UK | English, UK"
en_US = "en-US"
Expand Down Expand Up @@ -808,7 +808,7 @@ class Locale(Enum):
tr = "tr"
"Turkish | Türkçe"
uk = "uk"
"Ukrainian | Українська" # noqa: RUF001
"Ukrainian | Українська"
vi = "vi"
"Vietnamese | Tiếng Việt"
zh_CN = "zh-CN"
Expand Down
6 changes: 3 additions & 3 deletions disnake/errors.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, Dict, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Mapping, Optional, Tuple, Union

if TYPE_CHECKING:
from aiohttp import ClientResponse, ClientWebSocketResponse
Expand Down Expand Up @@ -225,7 +225,7 @@ class ConnectionClosed(ClientException):
"""

# https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes
GATEWAY_CLOSE_EVENT_REASONS: Dict[int, str] = {
GATEWAY_CLOSE_EVENT_REASONS: ClassVar[Mapping[int, str]] = {
4000: "Unknown error",
4001: "Unknown opcode",
4002: "Decode error",
Expand All @@ -243,7 +243,7 @@ class ConnectionClosed(ClientException):
}

# https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-close-event-codes
GATEWAY_VOICE_CLOSE_EVENT_REASONS: Dict[int, str] = {
GATEWAY_VOICE_CLOSE_EVENT_REASONS: ClassVar[Mapping[int, str]] = {
**GATEWAY_CLOSE_EVENT_REASONS,
4002: "Failed to decode payload",
4006: "Session no longer valid",
Expand Down
4 changes: 1 addition & 3 deletions disnake/ext/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,7 @@ def voice_client(self) -> Optional[VoiceProtocol]:
return g.voice_client if g else None

async def send_help(self, *args: Any) -> Any:
"""send_help(entity=<bot>)
|coro|
"""|coro|
Shows the help command for the specified entity if given.
The entity can be a command or a cog.
Expand Down
4 changes: 2 additions & 2 deletions disnake/ext/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import functools
import itertools
import re
from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Iterable, Mapping, Optional

import disnake.utils

Expand Down Expand Up @@ -279,7 +279,7 @@ class HelpCommand:
ones passed in the :class:`.Command` constructor.
"""

MENTION_TRANSFORMS = {
MENTION_TRANSFORMS: ClassVar[Mapping[str, str]] = {
"@everyone": "@\u200beveryone",
"@here": "@\u200bhere",
r"<@!?[0-9]{17,19}>": "@deleted-user",
Expand Down
4 changes: 2 additions & 2 deletions disnake/opus.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ def _load_default() -> bool:
_bitness = struct.calcsize("P") * 8
_target = "x64" if _bitness > 32 else "x86"
_filename = os.path.join(_basedir, "bin", f"libopus-0.{_target}.dll")
_lib = libopus_loader(_filename) # noqa: PLW0603
_lib = libopus_loader(_filename)
else:
path = ctypes.util.find_library("opus")
if not path:
raise AssertionError("could not find the opus library")
_lib = libopus_loader(path) # noqa: PLW0603
_lib = libopus_loader(path)
except Exception:
_lib = MISSING

Expand Down
10 changes: 6 additions & 4 deletions disnake/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def replacement(match):
regex = _MARKDOWN_STOCK_REGEX
if ignore_links:
regex = f"(?:{_URL_REGEX}|{regex})"
return re.sub(regex, replacement, text, 0, re.MULTILINE)
return re.sub(regex, replacement, text, flags=re.MULTILINE)


def escape_markdown(text: str, *, as_needed: bool = False, ignore_links: bool = True) -> str:
Expand Down Expand Up @@ -857,7 +857,7 @@ def replacement(match):
regex = _MARKDOWN_STOCK_REGEX
if ignore_links:
regex = f"(?:{_URL_REGEX}|{regex})"
return re.sub(regex, replacement, text, 0, re.MULTILINE)
return re.sub(regex, replacement, text, flags=re.MULTILINE)
else:
text = re.sub(r"\\", r"\\\\", text)
return _MARKDOWN_ESCAPE_REGEX.sub(r"\\\1", text)
Expand Down Expand Up @@ -1134,8 +1134,10 @@ def evaluate_annotation(
if implicit_str and isinstance(tp, str):
if tp in cache:
return cache[tp]
evaluated = eval( # noqa: PGH001 # this is how annotations are supposed to be unstringifed
tp, globals, locals
evaluated = (
eval( # noqa: PGH001, S307 # this is how annotations are supposed to be unstringifed
tp, globals, locals
)
)
cache[tp] = evaluated
return evaluate_annotation(evaluated, globals, locals, cache)
Expand Down
5 changes: 3 additions & 2 deletions docs/extensions/attributetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import inspect
import re
from collections import defaultdict
from typing import TYPE_CHECKING, DefaultDict, Dict, List, NamedTuple, Optional, Tuple
from typing import TYPE_CHECKING, ClassVar, DefaultDict, Dict, List, NamedTuple, Optional, Tuple

from docutils import nodes
from sphinx import addnodes
Expand All @@ -17,6 +17,7 @@
from _types import SphinxExtensionMeta
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment
from sphinx.util.typing import OptionSpec
from sphinx.writers.html import HTMLTranslator


Expand Down Expand Up @@ -100,7 +101,7 @@ class PyAttributeTable(SphinxDirective):
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = False
option_spec = {}
option_spec: ClassVar[OptionSpec] = {}

def parse_name(self, content: str) -> Tuple[str, Optional[str]]:
match = _name_parser_regex.match(content)
Expand Down
4 changes: 1 addition & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
"PDM_IGNORE_SAVED_PYTHON": "1",
},
)
# support the python parser in case the native parser isn't available
os.environ.setdefault("LIBCST_PARSER_TYPE", "native")


nox.options.error_on_external_run = True
Expand Down Expand Up @@ -204,7 +202,7 @@ def pyright(session: nox.Session) -> None:
pass


@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
@nox.session(python=["3.8", "3.9", "3.10", "3.11", "3.12"])
@nox.parametrize(
"extras",
[
Expand Down
22 changes: 15 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ tools = [
"python-dotenv~=1.0.0",
"towncrier==23.6.0",
"check-manifest==0.49",
"ruff==0.0.261",
"ruff==0.0.292",
]
codemod = [
# run codemods on the respository (mostly automated typing)
"libcst~=0.4.9",
"black==23.1.0",
"libcst~=1.1.0",
"black==23.9.1",
"autotyping==23.2.0",
]
typing = [
# this is not pyright itself, but the python wrapper
"pyright==1.1.291",
"typing-extensions~=4.5.0",
"typing-extensions~=4.8.0",
# only used for type-checking, version does not matter
"pytz",
]
test = [
"pytest~=7.2.1",
"pytest~=7.4.2",
"pytest-cov~=4.0.0",
"pytest-asyncio~=0.20.3",
"looptime~=0.2",
Expand Down Expand Up @@ -120,7 +120,7 @@ runner = "pdm run"

[tool.black]
line-length = 100
target-version = ["py38", "py39", "py310", "py311"]
target-version = ["py38", "py39", "py310", "py311", "py312"]

[tool.isort]
profile = "black"
Expand Down Expand Up @@ -177,16 +177,24 @@ ignore = [
"RUF005", # might not be actually faster
"RUF006", # might not be an issue/very extreme cases

# calling subprocess with dynamic arguments is generally fine, the only way to avoid this is ignoring it
"S603",

# partial executable paths (i.e. "git" instead of "/usr/bin/git") are fine
"S607",

# ignore try-except-pass. Bare excepts are caught with E722
"S110",

# provide specific codes on type: ignore
"PGH003",

# typevar names don't match variance (we don't always want this)
"PLC0105",

# import aliases are fixed by isort
"PLC0414",


# outer loop variables are overwritten by inner assignment target, these are mostly intentional
"PLW2901",

Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class C(A):
__slots__ = {"c": "uwu"}

class D(B, C):
__slots__ = "xyz"
__slots__ = "xyz" # noqa: PLC0205 # this is intentional

assert list(utils.get_slots(D)) == ["a", "a2", "c", "xyz"]

Expand Down

0 comments on commit 0fde8ae

Please sign in to comment.