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

feat: add 'py.typed' declaration #73

Merged
merged 1 commit into from
Nov 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mypy]
python_version = 3.6
exclude = tests/unit/resources/
13 changes: 13 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"lint",
"blacken",
"lint_setup_py",
"mypy",
"unit",
"check_lower_bounds"
]
Expand Down Expand Up @@ -74,6 +75,18 @@ def lint_setup_py(session):
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")


@nox.session(python="3.6")
def mypy(session):
"""Verify type hints are mypy compatible."""
session.install("-e", ".")
session.install(
"mypy",
"types-mock",
"types-setuptools",
)
session.run("mypy", "test_utils/", "tests/")


@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"])
def unit(session):
constraints_path = str(
Expand Down
3 changes: 2 additions & 1 deletion test_utils/lower_bound_checker/lower_bound_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def _get_package_requirements(package_name: str) -> List[Requirement]:
List[pkg_resources.Requirement]: A list of package requirements and extras.
"""
dist = pkg_resources.get_distribution(package_name)
requirements = [Requirement(str(r)) for r in dist.requires(extras=dist.extras)]
extras = tuple(dist.extras)
requirements = [Requirement(str(r)) for r in dist.requires(extras=extras)]

return requirements

Expand Down
3 changes: 2 additions & 1 deletion test_utils/prefixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import random
import re

from typing import Union

_RESOURCE_DATE_FORMAT = "%Y%m%d%H%M%S"
_RESOURCE_DATE_LENGTH = 4 + 2 + 2 + 2 + 2 + 2
Expand Down Expand Up @@ -61,7 +62,7 @@ def create_prefix(self) -> str:
random_string = hex(random.randrange(0x1000000))[2:]
return f"{self._prefix}{self._separator}{timestamp}{self._separator}{random_string}"

def _name_to_date(self, resource_name: str) -> datetime.datetime:
def _name_to_date(self, resource_name: str) -> Union[datetime.datetime, None]:
start_date = len(self._prefix) + len(self._separator)
date_string = resource_name[start_date : start_date + _RESOURCE_DATE_LENGTH]
try:
Expand Down
2 changes: 2 additions & 0 deletions test_utils/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# The test_utils package uses inline types.
4 changes: 2 additions & 2 deletions test_utils/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import sys
import time

import google.auth.credentials
from google.auth.environment_vars import CREDENTIALS as TEST_CREDENTIALS
import google.auth.credentials # type: ignore
from google.auth.environment_vars import CREDENTIALS as TEST_CREDENTIALS # type: ignore


# From shell environ. May be None.
Expand Down
2 changes: 1 addition & 1 deletion test_utils/vpcsc_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import os

import pytest
import pytest # type: ignore


INSIDE_VPCSC_ENVVAR = "GOOGLE_CLOUD_TESTS_IN_VPCSC"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_lower_bound_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import List

from click.testing import CliRunner
import pytest
import pytest # type: ignore

from test_utils.lower_bound_checker import lower_bound_checker

Expand All @@ -45,7 +45,7 @@ def parse_error_msg(msg: str) -> List[str]:
reqs = []

if match:
reqs = match.groups(1)[0].split(",")
reqs = match.groups(1)[0].split(",") # type: ignore
reqs = [r.strip().replace("'", "").replace('"', "") for r in reqs]

return reqs
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_orchestrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
try:
from unittest import mock
except ImportError: # pragma: NO PY3 COVER
import mock
import mock # type: ignore

import pytest
import pytest # type: ignore

from test_utils import orchestrate

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_prefixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import datetime
import re

import pytest
import pytest # type: ignore

import test_utils.prefixer

Expand Down