Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Python 3.10 #315

Merged
merged 15 commits into from
Aug 21, 2022
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ on:

jobs:
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- name: Cancel Outdated Runs
uses: styfle/cancel-workflow-action@0.10.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.10'
- uses: actions/cache@v3
with:
path: ~/.cache/pip
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:

jobs:
unit_test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, '3.10']

steps:
- name: Cancel Outdated Runs
Expand All @@ -35,10 +35,10 @@ jobs:
run: pytest -vv tests/unit_tests -n auto

integration_test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, '3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ coverage.xml
**/*.log
**/*.lock
test.py
.venv
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ flake8==5.0.4
isort==5.10.1
pytest==7.1.2
pytest-xdist==2.5.0
pytype==2021.10.18
pytype==2022.8.3
snapshottest==0.6.0
23 changes: 16 additions & 7 deletions mmpy_bot/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import re
from abc import ABC, abstractmethod
from typing import Callable, Optional, Sequence
from typing import Callable, Optional, Sequence, Union

import click

Expand All @@ -19,24 +19,32 @@
class Function(ABC):
def __init__(
self,
function: Callable,
function: Union[Function, click.command],
attzonko marked this conversation as resolved.
Show resolved Hide resolved
matcher: re.Pattern,
**metadata,
):
# If another Function was passed, keep track of all these siblings.
# We later use them to register not only the outermost Function, but also any
# stacked ones.
self.siblings = []

while isinstance(function, Function):
self.siblings.append(function)
function = function.function

# FIXME: After this while loop it is possible that function is not a Function, do we really want to assign self.function to something which is not a Function? Check if this is needed for the click.Command case
attzonko marked this conversation as resolved.
Show resolved Hide resolved
self.function = function
self.is_coroutine = asyncio.iscoroutinefunction(function)
self.is_click_function: bool = False
self.matcher = matcher
self.metadata = metadata

if not isinstance(function, click.command):
unode marked this conversation as resolved.
Show resolved Hide resolved
self.function.callback = None
self.function.get_help = None
self.function.make_context = None
self.function.invoke = None

# To be set in the child class or from the parent plugin
self.plugin = None
self.name: Optional[str] = None
Expand Down Expand Up @@ -85,6 +93,10 @@ def __init__(
else:
self.allowed_channels = [channel.lower() for channel in allowed_channels]

# Default for non-click functions
_function: Union[Callable, click.Command] = self.function
self.docstring = self.function.__doc__

if self.is_click_function:
_function = self.function.callback
if asyncio.iscoroutinefunction(_function):
Expand All @@ -100,11 +112,8 @@ def __init__(
self.docstring = self.function.get_help(ctx).replace(
"\n", f"\n{spaces(8)}"
)
else:
_function = self.function
self.docstring = self.function.__doc__

self.name = _function.__qualname__
if _function is not None:
self.name = _function.__qualname__

argspec = list(inspect.signature(_function).parameters.keys())
if not argspec[:2] == ["self", "message"]:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ exclude =
ignored
# Keep going past errors to analyse as many files as possible.
keep_going = True
python_version = 3.8
python_version = 3.10