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

Mypy typing + make API nice and unified #123

Merged
merged 7 commits into from
Jul 20, 2018
Merged

Mypy typing + make API nice and unified #123

merged 7 commits into from
Jul 20, 2018

Conversation

nbgl
Copy link
Contributor

@nbgl nbgl commented Jul 10, 2018

  1. Mypy typing for everyone!
    2dpgwn
  2. Bring Hamming similarity API in line with Dice coefficient API.

@nbgl nbgl added this to the Sprint 2018-07-13 milestone Jul 10, 2018
@nbgl nbgl self-assigned this Jul 10, 2018
@nbgl nbgl requested a review from hardbyte July 10, 2018 01:05
Copy link
Collaborator

@hardbyte hardbyte left a comment

Choose a reason for hiding this comment

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

Well typed! Thanks for your patience with the code review.

One comment that I think you should change but I'll approve now.

@@ -1,15 +1,17 @@
from abc import ABCMeta, abstractmethod
from itertools import chain, product, repeat
from numbers import Real
from numbers import Integral, Real
Copy link
Collaborator

Choose a reason for hiding this comment

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

Integral doesn't appear to be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed! Removed.

@@ -21,21 +23,22 @@ def _evalf(__funcs : 'Iterable[Callable[..., _T]]', # https://github.com/python
return (f(*args, **kwargs) for f in __funcs)


class _AssociativeBinaryOp(metaclass=ABCMeta):
__slots__ = '_funcs'
_Record = TypeVar('_Record')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why BlockingFunction but _Record? Shouldn't these be consistent? Shouldn't you import the _Record defined in typechecking.py?

Also I'd only put the TypeVar directly above a class declaration if it isn't used anywhere else - in this case _Record is used throughout the following classes so give it some whitespace to separate it from the first class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_Record is only there to parametrise the generic. It doesn’t make sense for other modules to import it. Similarly, _Record in typechecking.py is just there to parametrise generics. I don’t think it makes sense to import a parametrisation variable from elsewhere. But I’m open to discussion on this.

I’ve fixed the whitespace!

assert len(clk1) == len(clk2)
assert len(clk1) != 0
return sum(map(operator.eq, clk1, clk2)) / len(clk1)
return 1 - (clk1 ^ clk2).count() / len(clk1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

sneaky

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This kind of made sense to put there. I changed the type annotations to support only bitarrays instead of the more general Sequence[bool]. I thought the similarity code should reflect that.

@nbgl nbgl merged commit d1ec7a6 into api-new Jul 20, 2018
@nbgl nbgl deleted the api-new-typing branch July 20, 2018 02:27
nbgl added a commit that referenced this pull request Aug 1, 2018
* Blocking functions

* Minor docstring

* Types for Mypy

* Hamming similarity

* Refactor tests

* Minor refactor

* Require NumPy

* Multiparty greedy solver

* Candidate generation. Still missing some features

* Some optimisations

* More optimisation

* Still optimising

* Ready for PR

* Hamish PR comments

* Fix Python 3.5 bug

* Serialization

* Serialisation of candidate pairs!

* Update typechecking.

* Fix typing

* Fix tests on big numbers

* Oops. Minor.

* Minor comment

* Brian PR comments

* Bug fix + more Pythonic type checking

* Only test on >=Python3.6

* Travis does not yet have Python 3.7...

* GPU 1 does not yet have Python 3.7

* Hamish PR comments

* Revert release to Python 3.6

* I forgot to commit this before merging… (#119)

* Candidate generation refactor (#122)

* Candidate generation

* Minor docstring

* Typo in docstring

* Hamish PR Comments

* New API for Dice Coefficient (#121)

* New API for Dice Coefficient

* Docstrings

* Minor PEP8

* Typing

* Make tests pass…

* Brian PR comments

* Mypy typing + make API nice and unified (#123)

* Type hints

* Bring Hamming similarity in line with rest of API

* Make solver tests pass

* Ok, solving tests should finally work now...

* Brian PR comments

* Make typechecking.Record importable

* Add dependency on mypy extensions

* Blocking style (#125)

* Blocking style

* Minor commenting

* Improve coverage on edge cases + misc. testing (#127)

* Type hints

* Bring Hamming similarity in line with rest of API

* Make solver tests pass

* Ok, solving tests should finally work now...

* Edge cases and tests

* Restore old similarity tests

* Minor: I don't know how that typo got there

* Make Dice similarity tests pass with new Clkhash

* Minor: unused imports

* Style and docstrings (#130)

* Style and comments

* More style and comments

* Mypy

* Minor: Fix link

* Brian PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants