Skip to content

Update docs for 0.14 tag (#118) #119

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

Merged
merged 2 commits into from
May 16, 2019
Merged

Update docs for 0.14 tag (#118) #119

merged 2 commits into from
May 16, 2019

Conversation

mehaase
Copy link
Member

@mehaase mehaase commented May 14, 2019

Flesh out some missing pydocs, clean up the introduction, and make
the examples more common wsproto idioms.

@mehaase mehaase requested a review from pgjones May 14, 2019 12:52
@Kriechi
Copy link
Member

Kriechi commented May 14, 2019

Thanks! This looks great! 👍 🎉

@mehaase
Copy link
Member Author

mehaase commented May 14, 2019

The lint build failed but it failed on lines I didn't change. Is this a blocker?

@Kriechi
Copy link
Member

Kriechi commented May 14, 2019

Mhm I re-ran the job - it still fails. Might be an newer linter / updates rules?
There are only 3 errors - and they don't look particularly problematic to fix - would you mind taking a look?

@mehaase
Copy link
Member Author

mehaase commented May 14, 2019

I took a look but I'm not sure how to fix any of the errors. I'll paste here so we can discuss:

example/synchronous_client.py
  Line: 10
    pylint: import-error / Unable to import 'wsproto'

example/synchronous_server.py
  Line: 11
    pylint: import-error / Unable to import 'wsproto'

These two seem to be a configuration issue, like a bad $PYTHONPATH or $PWD. I'm not sure where that stuff is configured.

wsproto/__init__.py
  Line: 25
    pylint: syntax-error / misplaced type annotation (<unknown>, line 25)

The error refers to these lines in the constructor:

 # type: (ConnectionType) -> None
 self.client = connection_type is ConnectionType.CLIENT

I don't have any experience with type hints. Is that even valid way to type hint? It looks like a hint for a function but the field is a bool? I'm totally lost.

@pgjones
Copy link
Member

pgjones commented May 15, 2019

Looks great, I'd be happy to merge as is, but I think you should remove the type information in the docstrings as #116 adds them in a way that can be verified.

@pgjones
Copy link
Member

pgjones commented May 15, 2019

Regarding the linting issues, the wsproto/init.py line is removed in #116, it could also be removed here to pass the build.

I'm not sure we need to run pylint on the examples and I'm confused why these appear now?

@Kriechi
Copy link
Member

Kriechi commented May 15, 2019

I might have jumped the gun by merging #116 - and now we have a few conflicts here.. sorry 😄
@mehaase would you mind taking a look at resolving them?

The linting errors are not a blocker - we can fix (disable) them, after merging this PR.

Flesh out some missing pydocs, clean up the introduction, and make
the examples more common wsproto idioms.
@mehaase
Copy link
Member Author

mehaase commented May 16, 2019

@Kriechi I just rebased this branch so it can merge into master.

I noticed that master has some new type annotations and so the pydocs are redundant in some places with the type annotations. Here's an example from wsproto/__init__.py:

    def send(self, event: Event) -> bytes:
        """
        Generate network data for the specified event.

        When you want to communicate with a WebSocket peer, you should construct
        an event and pass it to this method. This method will return the bytes
        that you should send to the peer.

        :param wsproto.events.Event event: The event to generate data for
        :returns bytes: The data to send to the peer
        """
        data = b""
        if self.connection is None:
            data += self.handshake.send(event)
            self.connection = self.handshake.connection
        else:
            data += self.connection.send(event)
        return data

The type of the event argument is included as both a type hint and a pydoc. I would eliminate the redundancy by removing the pydoc, but it seems Sphinx will only create links for types in the pydoc. It won't link to a type in a type hint. Here's a picture of the rendered Sphinx docs:

screenshot of sphinx docs shows that pydoc is linked and type hint is not linked

It looks like there is a Sphinx plugin that might render type hints better, but I haven't ever used it before. It seems like a big enough change to warrant opening a separate issue.

@Kriechi Kriechi merged commit 1bfd3bb into python-hyper:master May 16, 2019
@Kriechi
Copy link
Member

Kriechi commented May 16, 2019

I don't mind the redundancy... at least for me, I'm still mostly looking at docstrings to figure out the expected types. Type hints have not been absorbed that deeply into my brain yet 😄

@Kriechi Kriechi mentioned this pull request May 16, 2019
@pgjones
Copy link
Member

pgjones commented May 17, 2019

I think the sphinx plugin is worth using and including (I'm hoping it works). Without it I would worry that the docstrings and type hints naturally diverge and add confusion over time.

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.

3 participants