Skip to content

Commit

Permalink
linting: update black and mypy with strict checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Kriechi committed Jun 21, 2021
1 parent e0a212c commit 1f87afc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 32 deletions.
4 changes: 2 additions & 2 deletions example/synchronous_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ def wsproto_demo(host: str, port: int) -> None:


def net_send(out_data: bytes, conn: socket.socket) -> None:
""" Write pending data from websocket to network. """
"""Write pending data from websocket to network."""
print("Sending {} bytes".format(len(out_data)))
conn.send(out_data)


def net_recv(ws: WSConnection, conn: socket.socket) -> None:
""" Read pending data from network into websocket. """
"""Read pending data from network into websocket."""
in_data = conn.recv(RECEIVE_BYTES)
if not in_data:
# A receive of zero bytes indicates the TCP socket has been closed. We
Expand Down
24 changes: 4 additions & 20 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,9 @@ no_lines_before=LOCALFOLDER
order_by_type=False

[mypy]
check_untyped_defs = True
disallow_any_decorated = True
disallow_any_explicit = True
# disallow_any_expr = True
disallow_any_generics = True
# disallow_any_unimported = True
disallow_incomplete_defs = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_decorators = True
disallow_untyped_defs = True
implicit_reexport = False
no_implicit_optional = True
show_error_codes = True
strict_equality = True
strict_optional = True
warn_redundant_casts = True
# warn_return_any = True
warn_unused_configs = True
warn_unused_ignores = True
strict = true
warn_unused_configs = true
show_error_codes = true

[mypy-h11.*]
ignore_missing_imports = True
2 changes: 1 addition & 1 deletion src/wsproto/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ConnectionState(Enum):


class ConnectionType(Enum):
""" An enumeration of connection types. """
"""An enumeration of connection types."""

#: This connection will act as client and talk to a remote server
CLIENT = 1
Expand Down
4 changes: 2 additions & 2 deletions src/wsproto/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class CloseConnection(Event):
reason: Optional[str] = None

def response(self) -> "CloseConnection":
""" Generate an RFC-compliant close frame to send back to the peer. """
"""Generate an RFC-compliant close frame to send back to the peer."""
return CloseConnection(code=self.code, reason=self.reason)


Expand Down Expand Up @@ -276,7 +276,7 @@ class Ping(Event):
payload: bytes = b""

def response(self) -> "Pong":
""" Generate an RFC-compliant :class:`Pong` response to this ping. """
"""Generate an RFC-compliant :class:`Pong` response to this ping."""
return Pong(payload=self.payload)


Expand Down
8 changes: 4 additions & 4 deletions src/wsproto/handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _accept(self, event: AcceptConnection) -> bytes:
event.extensions,
)
self._state = ConnectionState.OPEN
return self._h11_connection.send(response)
return self._h11_connection.send(response) # type: ignore[no-any-return]

def _reject(self, event: RejectConnection) -> bytes:
if self.state != ConnectionState.CONNECTING:
Expand All @@ -303,7 +303,7 @@ def _reject(self, event: RejectConnection) -> bytes:
if not event.has_body:
data += self._h11_connection.send(h11.EndOfMessage())
self._state = ConnectionState.CLOSED
return data
return data # type: ignore[no-any-return]

def _send_reject_data(self, event: RejectData) -> bytes:
if self.state != ConnectionState.REJECTING:
Expand All @@ -315,7 +315,7 @@ def _send_reject_data(self, event: RejectData) -> bytes:
if event.body_finished:
data += self._h11_connection.send(h11.EndOfMessage())
self._state = ConnectionState.CLOSED
return data
return data # type: ignore[no-any-return]

# Client mode methods

Expand Down Expand Up @@ -360,7 +360,7 @@ def _initiate_connection(self, request: Request) -> bytes:
target=request.target.encode("ascii"),
headers=headers + request.extra_headers,
)
return self._h11_connection.send(upgrade)
return self._h11_connection.send(upgrade) # type: ignore[no-any-return]

def _establish_client_connection(
self, event: h11.InformationalResponse
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ commands = pytest {posargs}
[testenv:lint]
deps =
flake8>=3.9.1,<4
black==20.8b1
black==21.5b2
isort==5.6.4
mypy==0.790
pytest==6.1.2
mypy==0.902
{[testenv]deps}
commands =
flake8 src/ test/
black --check --diff src/ test/ example/ compliance/ bench/
Expand Down

0 comments on commit 1f87afc

Please sign in to comment.