Skip to content

Commit

Permalink
Fix static typing issue & turn on mypy+pyright in adodbapi (#2279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Jun 30, 2024
1 parent 9ef5061 commit a9010f3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
5 changes: 2 additions & 3 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,8 @@ def __setattr__(self, name, value):
f"paramstyle={value!r} not in:{api.accepted_paramstyles!r}",
)
elif name == "variantConversions":
value = copy.copy(
value
) # make a new copy -- no changes in the default, please
# make a new copy -- no changes in the default, please
value = copy.copy(value)
object.__setattr__(self, name, value)

def __getattr__(self, item):
Expand Down
25 changes: 17 additions & 8 deletions adodbapi/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
* http://sourceforge.net/projects/adodbapi
"""

from __future__ import annotations

import datetime
import decimal
import numbers
import sys
import time
from collections.abc import Callable, Iterable, Mapping
from typing import Dict

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


class MultiMap(dict): # builds a dictionary from {(sequence,of,keys) : function}
"""A dictionary of ado.type : function -- but you can set multiple items by passing a sequence of keys"""
class MultiMap(Dict[int, Callable[[object], object]]):
# builds a dictionary from {(iterable,of,keys) : function}
"""A dictionary of ado.type : function
-- but you can set multiple items by passing an iterable of keys"""

# useful for defining conversion functions for groups of similar data types.
def __init__(self, aDict):
for k, v in list(aDict.items()):
def __init__(self, aDict: Mapping[Iterable[int] | int, Callable[[object], object]]):
for k, v in aDict.items():
self[k] = v # we must call __setitem__

def __setitem__(self, adoType, cvtFn):
"set a single item, or a whole sequence of items"
try: # user passed us a sequence, set them individually
def __setitem__(
self, adoType: Iterable[int] | int, cvtFn: Callable[[object], object]
):
"set a single item, or a whole iterable of items"
if isinstance(adoType, Iterable):
# user passed us an iterable, set them individually
for type in adoType:
dict.__setitem__(self, type, cvtFn)
except TypeError: # a single value fails attempt to iterate
else:
dict.__setitem__(self, adoType, cvtFn)


Expand Down
28 changes: 13 additions & 15 deletions adodbapi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
Adodbapi can be run on CPython 3.5 and later.
"""

CLASSIFIERS = """\
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
Operating System :: Microsoft :: Windows
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: SQL
Topic :: Software Development
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Database
"""

NAME = "adodbapi"
MAINTAINER = "Vernon Cole"
MAINTAINER_EMAIL = "vernondcole@gmail.com"
Expand All @@ -25,7 +11,19 @@
)
URL = "http://sourceforge.net/projects/adodbapi"
LICENSE = "LGPL"
CLASSIFIERS = filter(None, CLASSIFIERS.split("\n"))
CLASSIFIERS = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: SQL",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Database",
]
AUTHOR = "Henrik Ekelund, Vernon Cole, et.al."
AUTHOR_EMAIL = "vernondcole@gmail.com"
PLATFORMS = ["Windows", "Linux"]
Expand Down
2 changes: 0 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ exclude = (?x)(
| ^Pythonwin/Scintilla/
; Forked IDLE extensions predating Python 2.3. They now live in idlelib in https://github.com/python/cpython/tree/main/Lib/idlelib
| ^Pythonwin/pywin/idle/
; TODO: adodbapi should be updated and fixed separately
| ^adodbapi/
; TODO: Ignoring non-public APIs until all public API is typed
| ([Tt]est|[Dd]emos?)/
)
Expand Down
2 changes: 0 additions & 2 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"**/test/",
"**/Demos/",
"**/demo/",
// TODO: adodbapi should be updated and fixed separately
"adodbapi/",
],
// Packages that will be accessible globally.
// Setting this makes pyright use the repo's code for those modules instead of typeshed or pywin32 in site-packages
Expand Down

0 comments on commit a9010f3

Please sign in to comment.