Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static typing issue & turn on mypy+pyright in adodbapi #2279

Merged
merged 1 commit into from
Jun 30, 2024

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Jun 4, 2024

Work towards a typed API.

@Avasam Avasam requested a review from vernondcole June 4, 2024 20:34
@@ -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]]):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typing issue here was that dict leads to partially Any type. Since this is a very small and simple class, I completely typed it.

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():
Copy link
Collaborator Author

@Avasam Avasam Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ItemsView (or in the case of a dict, dict_items) is already iterable. coercing to a list was redundant.

@Avasam Avasam force-pushed the adodbapi-fix-static-typing-issue branch from ad5f536 to fd5cc25 Compare June 4, 2024 20:39
@Avasam Avasam added the adodbapi label Jun 4, 2024
Copy link
Collaborator

@vernondcole vernondcole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@Avasam Avasam merged commit a9010f3 into mhammond:main Jun 30, 2024
27 checks passed
@Avasam Avasam deleted the adodbapi-fix-static-typing-issue branch June 30, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants