Skip to content

Commit a9010f3

Browse files
authored
Fix static typing issue & turn on mypy+pyright in adodbapi (#2279)
1 parent 9ef5061 commit a9010f3

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

adodbapi/adodbapi.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,8 @@ def __setattr__(self, name, value):
418418
f"paramstyle={value!r} not in:{api.accepted_paramstyles!r}",
419419
)
420420
elif name == "variantConversions":
421-
value = copy.copy(
422-
value
423-
) # make a new copy -- no changes in the default, please
421+
# make a new copy -- no changes in the default, please
422+
value = copy.copy(value)
424423
object.__setattr__(self, name, value)
425424

426425
def __getattr__(self, item):

adodbapi/apibase.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
* http://sourceforge.net/projects/adodbapi
66
"""
77

8+
from __future__ import annotations
9+
810
import datetime
911
import decimal
1012
import numbers
1113
import sys
1214
import time
15+
from collections.abc import Callable, Iterable, Mapping
16+
from typing import Dict
1317

1418
# noinspection PyUnresolvedReferences
1519
from . import ado_consts as adc
@@ -461,20 +465,25 @@ def convert_to_python(variant, func): # convert DB value into Python value
461465
return func(variant) # call the appropriate conversion function
462466

463467

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"""
466472

467473
# 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():
470476
self[k] = v # we must call __setitem__
471477

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
475484
for type in adoType:
476485
dict.__setitem__(self, type, cvtFn)
477-
except TypeError: # a single value fails attempt to iterate
486+
else:
478487
dict.__setitem__(self, adoType, cvtFn)
479488

480489

adodbapi/setup.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@
33
Adodbapi can be run on CPython 3.5 and later.
44
"""
55

6-
CLASSIFIERS = """\
7-
Development Status :: 5 - Production/Stable
8-
Intended Audience :: Developers
9-
License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
10-
Operating System :: Microsoft :: Windows
11-
Operating System :: POSIX :: Linux
12-
Programming Language :: Python
13-
Programming Language :: Python :: 3
14-
Programming Language :: SQL
15-
Topic :: Software Development
16-
Topic :: Software Development :: Libraries :: Python Modules
17-
Topic :: Database
18-
"""
19-
206
NAME = "adodbapi"
217
MAINTAINER = "Vernon Cole"
228
MAINTAINER_EMAIL = "[email protected]"
@@ -25,7 +11,19 @@
2511
)
2612
URL = "http://sourceforge.net/projects/adodbapi"
2713
LICENSE = "LGPL"
28-
CLASSIFIERS = filter(None, CLASSIFIERS.split("\n"))
14+
CLASSIFIERS = [
15+
"Development Status :: 5 - Production/Stable",
16+
"Intended Audience :: Developers",
17+
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
18+
"Operating System :: Microsoft :: Windows",
19+
"Operating System :: POSIX :: Linux",
20+
"Programming Language :: Python",
21+
"Programming Language :: Python :: 3",
22+
"Programming Language :: SQL",
23+
"Topic :: Software Development",
24+
"Topic :: Software Development :: Libraries :: Python Modules",
25+
"Topic :: Database",
26+
]
2927
AUTHOR = "Henrik Ekelund, Vernon Cole, et.al."
3028
AUTHOR_EMAIL = "[email protected]"
3129
PLATFORMS = ["Windows", "Linux"]

mypy.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ exclude = (?x)(
4040
| ^Pythonwin/Scintilla/
4141
; Forked IDLE extensions predating Python 2.3. They now live in idlelib in https://github.com/python/cpython/tree/main/Lib/idlelib
4242
| ^Pythonwin/pywin/idle/
43-
; TODO: adodbapi should be updated and fixed separately
44-
| ^adodbapi/
4543
; TODO: Ignoring non-public APIs until all public API is typed
4644
| ([Tt]est|[Dd]emos?)/
4745
)

pyrightconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
"**/test/",
1717
"**/Demos/",
1818
"**/demo/",
19-
// TODO: adodbapi should be updated and fixed separately
20-
"adodbapi/",
2119
],
2220
// Packages that will be accessible globally.
2321
// Setting this makes pyright use the repo's code for those modules instead of typeshed or pywin32 in site-packages

0 commit comments

Comments
 (0)