Skip to content

Commit

Permalink
add #type ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
syumeikoukyo committed Mar 6, 2021
1 parent 0d7e041 commit 990dd08
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
11 changes: 7 additions & 4 deletions run-clang-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -22,9 +22,9 @@ def read(fname):
return fp.read()


requirements = []
requirements = [] # type: ignore

setup_requirements = []
setup_requirements = [] # type: ignore


setup(
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/algorithms/test_bounded_mean.py
Original file line number Diff line number Diff line change
@@ -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
)

Expand Down
19 changes: 10 additions & 9 deletions tests/algorithms/test_distributions.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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
)

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/algorithms/test_rand.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from pydp.util import Geometric, UniformDouble
from pydp.util import Geometric, UniformDouble # type: ignore


def test_rand_UniformDouble():
Expand Down

0 comments on commit 990dd08

Please sign in to comment.