From 990dd08fa5db1ace369522e857e2e0ae2e2b85e8 Mon Sep 17 00:00:00 2001 From: syumeikoukyo Date: Sat, 6 Mar 2021 09:12:33 +0900 Subject: [PATCH] add #type ignore --- run-clang-format.py | 11 +++++++---- setup.py | 12 ++++++------ tests/algorithms/test_bounded_mean.py | 4 ++-- tests/algorithms/test_distributions.py | 19 ++++++++++--------- tests/algorithms/test_rand.py | 2 +- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/run-clang-format.py b/run-clang-format.py index e10f6d08..f5e9f508 100755 --- a/run-clang-format.py +++ b/run-clang-format.py @@ -49,7 +49,7 @@ try: from subprocess import DEVNULL # py3k except ImportError: - DEVNULL = open(os.devnull, "wb") + DEVNULL = open(os.devnull, "wb") # type: ignore DEFAULT_EXTENSIONS = "c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx" @@ -101,7 +101,8 @@ def list_files(files, recursive=False, extensions=None, exclude=None): for x in dnames if not fnmatch.fnmatch(os.path.join(dirpath, x), pattern) ] - fpaths = [x for x in fpaths if not fnmatch.fnmatch(x, pattern)] + fpaths = [ + x for x in fpaths if not fnmatch.fnmatch(x, pattern)] for f in fpaths: ext = os.path.splitext(f)[1][1:] if ext in extensions: @@ -143,7 +144,8 @@ def run_clang_format_diff_wrapper(args, file): except DiffError: raise except Exception as e: - raise UnexpectedError("{}: {}: {}".format(file, e.__class__.__name__, e), e) + raise UnexpectedError("{}: {}: {}".format( + file, e.__class__.__name__, e), e) def run_clang_format_diff(args, file): @@ -374,7 +376,8 @@ def main(): pool = None else: pool = multiprocessing.Pool(njobs) - it = pool.imap_unordered(partial(run_clang_format_diff_wrapper, args), files) + it = pool.imap_unordered( + partial(run_clang_format_diff_wrapper, args), files) while True: try: outs, errs = next(it) diff --git a/setup.py b/setup.py index b2491ec2..88e09889 100644 --- a/setup.py +++ b/setup.py @@ -3,9 +3,9 @@ """The setup script.""" -from setuptools import setup, find_packages -from setuptools.dist import Distribution -from setuptools.command.install import install +from setuptools import setup, find_packages # type: ignore +from setuptools.dist import Distribution # type: ignore +from setuptools.command.install import install # type: ignore import os @@ -22,9 +22,9 @@ def read(fname): return fp.read() -requirements = [] +requirements = [] # type: ignore -setup_requirements = [] +setup_requirements = [] # type: ignore setup( @@ -50,7 +50,7 @@ def read(fname): keywords="pydp", name="python-dp", package_dir={"": "src"}, - package_data={"pydp": ["_pydp.so", "_pydp.pyd"],}, + package_data={"pydp": ["_pydp.so", "_pydp.pyd"], }, packages=find_packages(where="src", exclude=["tests"]), setup_requires=setup_requirements, test_suite="tests", diff --git a/tests/algorithms/test_bounded_mean.py b/tests/algorithms/test_bounded_mean.py index 4210b650..56b70d4c 100644 --- a/tests/algorithms/test_bounded_mean.py +++ b/tests/algorithms/test_bounded_mean.py @@ -1,10 +1,10 @@ import os import pytest from pydp.algorithms.laplacian import BoundedMean -from pydp._pydp import Summary +from pydp._pydp import Summary # type: ignore -expect_near = lambda expected, actual, tol: ( +def expect_near(expected, actual, tol): return ( expected + tol >= actual and expected - tol <= actual ) diff --git a/tests/algorithms/test_distributions.py b/tests/algorithms/test_distributions.py index d36ba908..4aa51e1a 100644 --- a/tests/algorithms/test_distributions.py +++ b/tests/algorithms/test_distributions.py @@ -1,9 +1,7 @@ import pytest -from pydp.distributions import ( - LaplaceDistribution, - GaussianDistribution, - GeometricDistribution, -) +from pydp.distributions import LaplaceDistribution # type: ignore +from pydp.distributions import GaussianDistribution # type: ignore +from pydp.distributions import GeometricDistribution # type: ignore import pydp as dp import math from typing import List @@ -24,7 +22,8 @@ def skew(samples: List[float], mu: float, sigma: float): Until then this should suffice. #FIXME: when possible we can fix this. """ skew = list( - accumulate(samples, lambda lhs, rhs: lhs + (rhs - mu) * (rhs - mu) * (rhs - mu)) + accumulate(samples, lambda lhs, rhs: lhs + + (rhs - mu) * (rhs - mu) * (rhs - mu)) )[-1] return skew / (len(samples) * sigma * sigma * sigma) @@ -36,7 +35,8 @@ def kurtosis(samples: List[float], mu: float, var: float): Until then this should suffice. #FIXME: when possible we can fix this. """ kurt = list( - accumulate(samples, lambda lhs, rhs: lhs + ((rhs - mu) * (rhs - mu)) ** 2) + accumulate(samples, lambda lhs, rhs: lhs + + ((rhs - mu) * (rhs - mu)) ** 2) )[-1] n = len(samples) kurt = (n + 1) * kurt / (n * var * var) @@ -48,7 +48,7 @@ def kurtosis(samples: List[float], mu: float, var: float): # From what I understand @openmined/dp-research are going to look at validating correctness # Until then we can use this to assert on floating point numbers. # FIXME: When possible we should add 'correctness' tests. -expect_near = lambda expected, actual, tol: ( +def expect_near(expected, actual, tol): return ( expected + tol >= actual and expected - tol <= actual ) @@ -62,7 +62,8 @@ def test_diversity_getter(self): def test_check_statistics_for_geo_unit_values(self): ld = LaplaceDistribution(epsilon=1.0, sensitivity=1.0) - samples = [ld.sample(scale=1.0) for _ in range(k_num_geometric_samples)] + samples = [ld.sample(scale=1.0) + for _ in range(k_num_geometric_samples)] mean = dp.util.mean(samples) var = dp.util.variance(samples) diff --git a/tests/algorithms/test_rand.py b/tests/algorithms/test_rand.py index 21c67770..3851465a 100644 --- a/tests/algorithms/test_rand.py +++ b/tests/algorithms/test_rand.py @@ -1,5 +1,5 @@ import pytest -from pydp.util import Geometric, UniformDouble +from pydp.util import Geometric, UniformDouble # type: ignore def test_rand_UniformDouble():