Queer European MD passionate about IT
Pārlūkot izejas kodu

Pass only supported arguments to async_wrapped coroutines

Davte 6 gadi atpakaļ
vecāks
revīzija
9c008d5923
2 mainītis faili ar 15 papildinājumiem un 2 dzēšanām
  1. 1 1
      davtelepot/__init__.py
  2. 14 1
      davtelepot/utilities.py

+ 1 - 1
davtelepot/__init__.py

@@ -7,7 +7,7 @@ __author__ = "Davide Testa"
 __email__ = "davide@davte.it"
 __email__ = "davide@davte.it"
 __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
 __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
 __license__ = "GNU General Public License v3.0"
 __license__ = "GNU General Public License v3.0"
-__version__ = "2.0.7"
+__version__ = "2.0.8"
 __maintainer__ = "Davide Testa"
 __maintainer__ = "Davide Testa"
 __contact__ = "t.me/davte"
 __contact__ = "t.me/davte"
 
 

+ 14 - 1
davtelepot/utilities.py

@@ -6,6 +6,7 @@ import collections
 import csv
 import csv
 import datetime
 import datetime
 from difflib import SequenceMatcher
 from difflib import SequenceMatcher
+import inspect
 import json
 import json
 import logging
 import logging
 import os
 import os
@@ -437,6 +438,8 @@ async def async_wrapper(coroutine, *args1, **kwargs1):
 
 
     Set some of the arguments, let the coroutine be awaited with the rest of
     Set some of the arguments, let the coroutine be awaited with the rest of
         them later.
         them later.
+    The wrapped coroutine will always pass only supported parameters to
+        `coroutine`.
     Example:
     Example:
     ```
     ```
         import asyncio
         import asyncio
@@ -456,7 +459,17 @@ async def async_wrapper(coroutine, *args1, **kwargs1):
     ```
     ```
     """
     """
     async def wrapped_coroutine(*args2, **kwargs2):
     async def wrapped_coroutine(*args2, **kwargs2):
-        return await coroutine(*args1, *args2, **kwargs1, **kwargs2)
+        # Update keyword arguments
+        kwargs1.update(kwargs2)
+        # Pass only supported arguments
+        kwargs = {
+            name: argument
+            for name, argument in kwargs1.items()
+            if name in inspect.signature(
+                coroutine
+            ).parameters
+        }
+        return await coroutine(*args1, *args2, **kwargs)
     return wrapped_coroutine
     return wrapped_coroutine