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

Node annotations #3396

Merged
merged 7 commits into from
Feb 5, 2019
Merged

Conversation

hackaugusto
Copy link
Contributor

No description provided.

Copy link
Contributor

@LefterisJP LefterisJP left a comment

Choose a reason for hiding this comment

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

Looks good to me. -- From the test failures I got another question.

Got the question on the assertions. Will also push a linting fix to make the build green.

if type(state_change) == Block:
assert isinstance(state_change, Block), MYPY_ANNOTATION
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm but why is the assert needed here and in all the files below? Shouldn't the if type(state_change) == X: be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should, but it isn't. mypy does not detect it.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's funny. I guess shortcomings of mypy they will hopefully eventually fix. Or ... could it be a subtle different of type() vs isinstance()? I am just theorizing here. Did not test this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm actually my theory seems to be correct. Let me open a PR for this.

This only throws warning for the type() check:

from typing import Union


class Boo(object):
    a = 1


class Foo(object):
    b = 2


def fun(f: Union[Foo, Boo]):
    if type(f) == Foo:
        print(f.b)

    if isinstance(f, Boo):
        print(f.a)

@@ -528,7 +528,7 @@ def from_dict(cls, data: Dict[str, Any]) -> 'TokenNetworkState':
serialization.identity,
data['partneraddresses_to_channelidentifiers'],
)
restored.partneraddresses_to_channelidentifiers = defaultdict(
restored.partneraddresses_to_channelidentifiers = defaultdict( # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

What was this complaining about?

Copy link
Contributor Author

@hackaugusto hackaugusto Feb 5, 2019

Choose a reason for hiding this comment

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

type mismatch. defaultdict is not a generic.

edit: I tried to fix the annotation, but at some point I just gave up and decided to leave it for the future, eventually defaultdict should be made generic too.

ST = TypeVar('ST', bound=State)


class TransitionResult(Generic[ST]): # pylint: disable=unsubscriptable-object
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice use of generic. Note that at the next release of pylint we can remove this disable pragma. This is a bug on the pylint side: pylint-dev/pylint#2416

@LefterisJP
Copy link
Contributor

@hackaugusto Have a look at this when you can. Build is now green.

@codecov-io
Copy link

codecov-io commented Feb 5, 2019

Codecov Report

Merging #3396 into master will decrease coverage by 0.05%.
The diff coverage is 94.64%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3396      +/-   ##
==========================================
- Coverage   75.92%   75.87%   -0.06%     
==========================================
  Files          97       97              
  Lines       12565    12604      +39     
  Branches     1760     1760              
==========================================
+ Hits         9540     9563      +23     
- Misses       2396     2410      +14     
- Partials      629      631       +2
Impacted Files Coverage Δ
raiden/transfer/state.py 68.64% <100%> (ø) ⬆️
raiden/transfer/architecture.py 79.31% <100%> (+0.24%) ⬆️
raiden/transfer/node.py 85.71% <94%> (+0.88%) ⬆️
raiden/utils/__init__.py 68.42% <0%> (-4.52%) ⬇️
raiden/network/transport/matrix.py 71.4% <0%> (-1.09%) ⬇️
raiden/transfer/mediated_transfer/events.py 83.17% <0%> (-0.94%) ⬇️
raiden/transfer/events.py 73.59% <0%> (-0.41%) ⬇️
raiden/messages.py 88.48% <0%> (+0.19%) ⬆️
raiden/network/transport/udp/udp_transport.py 91.09% <0%> (+0.8%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ed3216f...9830843. Read the comment docs.

raiden/transfer/node.py Outdated Show resolved Hide resolved
@hackaugusto
Copy link
Contributor Author

@LefterisJP thanks, looks good to me. However, I cannot approve my own PR, so if it's also good for you, please accept it :)

Copy link
Contributor

@rakanalh rakanalh left a comment

Choose a reason for hiding this comment

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

I am assuming that @LefterisJP is good with this PR... from my side it's LGTM.

@rakanalh rakanalh merged commit cb9c768 into raiden-network:master Feb 5, 2019
@hackaugusto hackaugusto deleted the node_annotations branch February 5, 2019 20:21
@LefterisJP
Copy link
Contributor

@rakanalh @LefterisJP yeah yeah sorry guys, forgot to approve since I was the last commiter in the branch. Apologies.

LefterisJP added a commit to LefterisJP/raiden that referenced this pull request Feb 5, 2019
This was prompted from the discussion made
[here](raiden-network#3396 (comment))

And the documentation of mypy also states that `isinstance()` checks
should be preferred for the same reason. [Source](https://mypy.readthedocs.io/en/latest/common_issues.html#complex-type-tests)
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.

4 participants