diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5498d66d..841659f5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,7 +13,7 @@ on: jobs: lint: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Cancel Outdated Runs @@ -21,10 +21,10 @@ jobs: 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 35032217..90dd3dee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index a924db41..b14c8108 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ coverage.xml **/*.log **/*.lock test.py +.venv diff --git a/dev-requirements.txt b/dev-requirements.txt index b42496a9..f4ee43af 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -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 diff --git a/mmpy_bot/function.py b/mmpy_bot/function.py index dee34035..42971009 100644 --- a/mmpy_bot/function.py +++ b/mmpy_bot/function.py @@ -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 @@ -19,7 +19,7 @@ class Function(ABC): def __init__( self, - function: Callable, + function: Union[Function, click.command], matcher: re.Pattern, **metadata, ): @@ -27,16 +27,24 @@ def __init__( # 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 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): + 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 @@ -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): @@ -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"]: diff --git a/setup.cfg b/setup.cfg index 85417023..747375da 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/setup.py b/setup.py index 780a9094..13e6eed6 100644 --- a/setup.py +++ b/setup.py @@ -43,6 +43,7 @@ def requires(filename: str): "Operating System :: OS Independent", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules", ],