mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-09-28 04:09:01 +00:00
chore: upgrade to mypy 1.0.0
Now that mypy 1.0.0 is out, we can get add some elegant type aliases for filter and action callback functions.
This commit is contained in:
parent
4b14d20c5e
commit
561460ec7f
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# This file is autogenerated by pip-compile with Python 3.8
|
# This file is autogenerated by pip-compile with Python 3.10
|
||||||
# by the following command:
|
# by the following command:
|
||||||
#
|
#
|
||||||
# pip-compile requirements/base.in
|
# pip-compile requirements/base.in
|
||||||
@ -26,7 +26,7 @@ kubernetes==25.3.0
|
|||||||
# via -r requirements/base.in
|
# via -r requirements/base.in
|
||||||
markupsafe==2.1.1
|
markupsafe==2.1.1
|
||||||
# via jinja2
|
# via jinja2
|
||||||
mypy==0.991
|
mypy==1.0.0
|
||||||
# via -r requirements/base.in
|
# via -r requirements/base.in
|
||||||
mypy-extensions==0.4.3
|
mypy-extensions==0.4.3
|
||||||
# via mypy
|
# via mypy
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
# This file is autogenerated by pip-compile with python 3.8
|
# This file is autogenerated by pip-compile with Python 3.10
|
||||||
# To update, run:
|
# by the following command:
|
||||||
#
|
#
|
||||||
# pip-compile requirements/dev.in
|
# pip-compile requirements/dev.in
|
||||||
#
|
#
|
||||||
@ -92,7 +92,7 @@ mccabe==0.7.0
|
|||||||
# via pylint
|
# via pylint
|
||||||
more-itertools==9.0.0
|
more-itertools==9.0.0
|
||||||
# via jaraco-classes
|
# via jaraco-classes
|
||||||
mypy==0.991
|
mypy==1.0.0
|
||||||
# via -r requirements/base.txt
|
# via -r requirements/base.txt
|
||||||
mypy-extensions==0.4.3
|
mypy-extensions==0.4.3
|
||||||
# via
|
# via
|
||||||
@ -204,11 +204,7 @@ types-setuptools==65.6.0.2
|
|||||||
typing-extensions==4.4.0
|
typing-extensions==4.4.0
|
||||||
# via
|
# via
|
||||||
# -r requirements/base.txt
|
# -r requirements/base.txt
|
||||||
# astroid
|
|
||||||
# black
|
|
||||||
# mypy
|
# mypy
|
||||||
# pylint
|
|
||||||
# rich
|
|
||||||
urllib3==1.26.13
|
urllib3==1.26.13
|
||||||
# via
|
# via
|
||||||
# -r requirements/base.txt
|
# -r requirements/base.txt
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# This file is autogenerated by pip-compile with Python 3.8
|
# This file is autogenerated by pip-compile with Python 3.10
|
||||||
# by the following command:
|
# by the following command:
|
||||||
#
|
#
|
||||||
# pip-compile requirements/docs.in
|
# pip-compile requirements/docs.in
|
||||||
@ -42,8 +42,6 @@ idna==3.4
|
|||||||
# requests
|
# requests
|
||||||
imagesize==1.4.1
|
imagesize==1.4.1
|
||||||
# via sphinx
|
# via sphinx
|
||||||
importlib-metadata==6.0.0
|
|
||||||
# via sphinx
|
|
||||||
jinja2==3.1.2
|
jinja2==3.1.2
|
||||||
# via
|
# via
|
||||||
# -r requirements/base.txt
|
# -r requirements/base.txt
|
||||||
@ -54,7 +52,7 @@ markupsafe==2.1.1
|
|||||||
# via
|
# via
|
||||||
# -r requirements/base.txt
|
# -r requirements/base.txt
|
||||||
# jinja2
|
# jinja2
|
||||||
mypy==0.991
|
mypy==1.0.0
|
||||||
# via -r requirements/base.txt
|
# via -r requirements/base.txt
|
||||||
mypy-extensions==0.4.3
|
mypy-extensions==0.4.3
|
||||||
# via
|
# via
|
||||||
@ -149,8 +147,6 @@ websocket-client==1.4.2
|
|||||||
# via
|
# via
|
||||||
# -r requirements/base.txt
|
# -r requirements/base.txt
|
||||||
# kubernetes
|
# kubernetes
|
||||||
zipp==3.11.0
|
|
||||||
# via importlib-metadata
|
|
||||||
|
|
||||||
# The following packages are considered to be unsafe in a requirements file:
|
# The following packages are considered to be unsafe in a requirements file:
|
||||||
# setuptools
|
# setuptools
|
||||||
|
@ -14,15 +14,13 @@ from .contexts import Contextualized
|
|||||||
#: Action generic signature.
|
#: Action generic signature.
|
||||||
T = ParamSpec("T")
|
T = ParamSpec("T")
|
||||||
|
|
||||||
# Similarly to CallableFilter, it should be possible to create a CallableAction alias in
|
ActionCallbackFunc = t.Callable[T, None]
|
||||||
# the future.
|
|
||||||
# CallableAction = t.Callable[T, None]
|
|
||||||
|
|
||||||
|
|
||||||
class ActionCallback(Contextualized, t.Generic[T]):
|
class ActionCallback(Contextualized, t.Generic[T]):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
func: t.Callable[T, None],
|
func: ActionCallbackFunc[T],
|
||||||
priority: t.Optional[int] = None,
|
priority: t.Optional[int] = None,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -75,7 +73,7 @@ class Action(t.Generic[T]):
|
|||||||
|
|
||||||
def add(
|
def add(
|
||||||
self, priority: t.Optional[int] = None
|
self, priority: t.Optional[int] = None
|
||||||
) -> t.Callable[[t.Callable[T, None]], t.Callable[T, None]]:
|
) -> t.Callable[[ActionCallbackFunc[T]], ActionCallbackFunc[T]]:
|
||||||
"""
|
"""
|
||||||
Decorator to add a callback to an action.
|
Decorator to add a callback to an action.
|
||||||
|
|
||||||
@ -97,7 +95,7 @@ class Action(t.Generic[T]):
|
|||||||
to return any value. Returned values will be ignored.
|
to return any value. Returned values will be ignored.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def inner(func: t.Callable[T, None]) -> t.Callable[T, None]:
|
def inner(func: ActionCallbackFunc[T]) -> ActionCallbackFunc[T]:
|
||||||
callback = ActionCallback(func, priority=priority)
|
callback = ActionCallback(func, priority=priority)
|
||||||
priorities.insert_callback(callback, self.callbacks)
|
priorities.insert_callback(callback, self.callbacks)
|
||||||
return func
|
return func
|
||||||
@ -218,7 +216,7 @@ def get_template(name: str) -> ActionTemplate[t.Any]:
|
|||||||
|
|
||||||
def add(
|
def add(
|
||||||
name: str, priority: t.Optional[int] = None
|
name: str, priority: t.Optional[int] = None
|
||||||
) -> t.Callable[[t.Callable[T, None]], t.Callable[T, None]]:
|
) -> t.Callable[[ActionCallbackFunc[T]], ActionCallbackFunc[T]]:
|
||||||
"""
|
"""
|
||||||
Decorator to add a callback action associated to a name.
|
Decorator to add a callback action associated to a name.
|
||||||
"""
|
"""
|
||||||
|
@ -17,16 +17,13 @@ T2 = ParamSpec("T2")
|
|||||||
#: Specialized typevar for list elements
|
#: Specialized typevar for list elements
|
||||||
L = t.TypeVar("L")
|
L = t.TypeVar("L")
|
||||||
|
|
||||||
# I wish we could create such an alias, which would greatly simply the definitions
|
FilterCallbackFunc = t.Callable[Concatenate[T1, T2], T1]
|
||||||
# below. Unfortunately this does not work, yet. It will once the following issue is
|
|
||||||
# resolved: https://github.com/python/mypy/issues/11855
|
|
||||||
# CallableFilter = t.Callable[Concatenate[T1, T2], T1]
|
|
||||||
|
|
||||||
|
|
||||||
class FilterCallback(contexts.Contextualized, t.Generic[T1, T2]):
|
class FilterCallback(contexts.Contextualized, t.Generic[T1, T2]):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
func: t.Callable[Concatenate[T1, T2], T1],
|
func: FilterCallbackFunc[T1, T2],
|
||||||
priority: t.Optional[int] = None,
|
priority: t.Optional[int] = None,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -83,9 +80,7 @@ class Filter(t.Generic[T1, T2]):
|
|||||||
|
|
||||||
def add(
|
def add(
|
||||||
self, priority: t.Optional[int] = None
|
self, priority: t.Optional[int] = None
|
||||||
) -> t.Callable[
|
) -> t.Callable[[FilterCallbackFunc[T1, T2]], FilterCallbackFunc[T1, T2]]:
|
||||||
[t.Callable[Concatenate[T1, T2], T1]], t.Callable[Concatenate[T1, T2], T1]
|
|
||||||
]:
|
|
||||||
"""
|
"""
|
||||||
Decorator to add a filter callback.
|
Decorator to add a filter callback.
|
||||||
|
|
||||||
@ -112,10 +107,8 @@ class Filter(t.Generic[T1, T2]):
|
|||||||
final_value = my_filter.apply(initial_value, some_other_argument_value)
|
final_value = my_filter.apply(initial_value, some_other_argument_value)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def inner(
|
def inner(func: FilterCallbackFunc[T1, T2]) -> FilterCallbackFunc[T1, T2]:
|
||||||
func: t.Callable[Concatenate[T1, T2], T1]
|
callback: FilterCallback[T1, T2] = FilterCallback(func, priority=priority)
|
||||||
) -> t.Callable[Concatenate[T1, T2], T1]:
|
|
||||||
callback = FilterCallback(func, priority=priority)
|
|
||||||
priorities.insert_callback(callback, self.callbacks)
|
priorities.insert_callback(callback, self.callbacks)
|
||||||
return func
|
return func
|
||||||
|
|
||||||
@ -318,9 +311,7 @@ def get_template(name: str) -> FilterTemplate[t.Any, t.Any]:
|
|||||||
|
|
||||||
def add(
|
def add(
|
||||||
name: str, priority: t.Optional[int] = None
|
name: str, priority: t.Optional[int] = None
|
||||||
) -> t.Callable[
|
) -> t.Callable[[FilterCallbackFunc[T1, T2]], FilterCallbackFunc[T1, T2]]:
|
||||||
[t.Callable[Concatenate[T1, T2], T1]], t.Callable[Concatenate[T1, T2], T1]
|
|
||||||
]:
|
|
||||||
"""
|
"""
|
||||||
Decorator for functions that will be applied to a single named filter.
|
Decorator for functions that will be applied to a single named filter.
|
||||||
"""
|
"""
|
||||||
|
@ -212,7 +212,7 @@ class Filters:
|
|||||||
#: - ``path`` is a tuple that corresponds to a template relative path.
|
#: - ``path`` is a tuple that corresponds to a template relative path.
|
||||||
#: Example: ``("myplugin", "hooks", "myservice", "pre-init")`` (see :py:data:`IMAGES_BUILD`).
|
#: Example: ``("myplugin", "hooks", "myservice", "pre-init")`` (see :py:data:`IMAGES_BUILD`).
|
||||||
#: The command to execute will be read from that template, after it is rendered.
|
#: The command to execute will be read from that template, after it is rendered.
|
||||||
COMMANDS_INIT: Filter[list[tuple[str, tuple[str, ...]]], str] = filters.get(
|
COMMANDS_INIT: Filter[list[tuple[str, tuple[str, ...]]], []] = filters.get(
|
||||||
"commands:init"
|
"commands:init"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user