|
5 | 5 | * http://sourceforge.net/projects/adodbapi |
6 | 6 | """ |
7 | 7 |
|
| 8 | +from __future__ import annotations |
| 9 | + |
8 | 10 | import datetime |
9 | 11 | import decimal |
10 | 12 | import numbers |
11 | 13 | import sys |
12 | 14 | import time |
| 15 | +from collections.abc import Callable, Iterable, Mapping |
| 16 | +from typing import Dict |
13 | 17 |
|
14 | 18 | # noinspection PyUnresolvedReferences |
15 | 19 | from . import ado_consts as adc |
@@ -461,20 +465,25 @@ def convert_to_python(variant, func): # convert DB value into Python value |
461 | 465 | return func(variant) # call the appropriate conversion function |
462 | 466 |
|
463 | 467 |
|
464 | | -class MultiMap(dict): # builds a dictionary from {(sequence,of,keys) : function} |
465 | | - """A dictionary of ado.type : function -- but you can set multiple items by passing a sequence of keys""" |
| 468 | +class MultiMap(Dict[int, Callable[[object], object]]): |
| 469 | + # builds a dictionary from {(iterable,of,keys) : function} |
| 470 | + """A dictionary of ado.type : function |
| 471 | + -- but you can set multiple items by passing an iterable of keys""" |
466 | 472 |
|
467 | 473 | # useful for defining conversion functions for groups of similar data types. |
468 | | - def __init__(self, aDict): |
469 | | - for k, v in list(aDict.items()): |
| 474 | + def __init__(self, aDict: Mapping[Iterable[int] | int, Callable[[object], object]]): |
| 475 | + for k, v in aDict.items(): |
470 | 476 | self[k] = v # we must call __setitem__ |
471 | 477 |
|
472 | | - def __setitem__(self, adoType, cvtFn): |
473 | | - "set a single item, or a whole sequence of items" |
474 | | - try: # user passed us a sequence, set them individually |
| 478 | + def __setitem__( |
| 479 | + self, adoType: Iterable[int] | int, cvtFn: Callable[[object], object] |
| 480 | + ): |
| 481 | + "set a single item, or a whole iterable of items" |
| 482 | + if isinstance(adoType, Iterable): |
| 483 | + # user passed us an iterable, set them individually |
475 | 484 | for type in adoType: |
476 | 485 | dict.__setitem__(self, type, cvtFn) |
477 | | - except TypeError: # a single value fails attempt to iterate |
| 486 | + else: |
478 | 487 | dict.__setitem__(self, adoType, cvtFn) |
479 | 488 |
|
480 | 489 |
|
|
0 commit comments