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

Type annotations #813

Merged
merged 6 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ isort:
isort tests
isort examples

flake: .flake
lint: .lint

.flake: $(shell find aiopg -type f) \
.lint: $(shell find aiopg -type f) \
$(shell find tests -type f) \
$(shell find examples -type f)
flake8 aiopg tests examples
Expand All @@ -24,6 +24,9 @@ flake: .flake
isort --diff aiopg tests examples; \
false; \
fi
@if ! mypy --strict --ignore-missing-imports --exclude sa aiopg; then \
echo "Typing errors"; \
fi

test: flake
pytest -q tests
Expand Down
37 changes: 31 additions & 6 deletions aiopg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
from collections import namedtuple

from .connection import TIMEOUT as DEFAULT_TIMEOUT
from .connection import Connection, connect
from .cursor import Cursor
from .connection import (
Connection,
Cursor,
DefaultCompiler,
IsolationCompiler,
IsolationLevel,
ReadCommittedCompiler,
RepeatableReadCompiler,
SerializableCompiler,
Transaction,
connect,
)
from .pool import Pool, create_pool
from .transaction import IsolationLevel, Transaction
from .utils import get_running_loop

warnings.filterwarnings(
Expand All @@ -29,14 +38,16 @@
'major minor micro releaselevel serial')


def _parse_version(ver):
def _parse_version(ver: str) -> VersionInfo:
RE = (
r'^'
r'(?P<major>\d+)\.(?P<minor>\d+)\.(?P<micro>\d+)'
r'((?P<releaselevel>[a-z]+)(?P<serial>\d+)?)?'
r'$'
)
match = re.match(RE, ver)
if not match:
raise ImportError(f"Invalid package version {ver}")
try:
major = int(match.group('major'))
minor = int(match.group('minor'))
Expand All @@ -55,5 +66,19 @@ def _parse_version(ver):
version_info = _parse_version(__version__)

# make pyflakes happy
(connect, create_pool, Connection, Cursor, Pool, DEFAULT_TIMEOUT,
IsolationLevel, Transaction, get_running_loop)
(
connect,
create_pool,
Connection,
Cursor,
Pool,
DEFAULT_TIMEOUT,
IsolationLevel,
Transaction,
get_running_loop,
IsolationCompiler,
DefaultCompiler,
ReadCommittedCompiler,
RepeatableReadCompiler,
SerializableCompiler
)
Loading