Skip to content

Commit

Permalink
fix: PEP 484 prohibits implicit Optional
Browse files Browse the repository at this point in the history
Problem:

    PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
    https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase

Solution:

    ./venv/bin/pip install no_implicit_optional
    ./venv/bin/no_implicit_optional pynvim
  • Loading branch information
justinmk committed Jul 14, 2023
1 parent 919217d commit 991c689
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
10 changes: 5 additions & 5 deletions pynvim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import sys
from types import SimpleNamespace as Version
from typing import List, cast, overload
from typing import List, Optional, cast, overload

from pynvim.api import Nvim, NvimError
from pynvim.msgpack_rpc import (ErrorResponse, Session, TTransportType, child_session,
Expand All @@ -28,7 +28,7 @@
'ErrorResponse')


def start_host(session: Session = None) -> None:
def start_host(session: Optional[Session] = None) -> None:
"""Promote the current process into python plugin host for Nvim.
Start msgpack-rpc event loop for `session`, listening for Nvim requests
Expand Down Expand Up @@ -101,10 +101,10 @@ def attach(session_type: Literal['stdio']) -> Nvim: ...

def attach(
session_type: TTransportType,
address: str = None,
address: Optional[str] = None,
port: int = 7450,
path: str = None,
argv: List[str] = None,
path: Optional[str] = None,
argv: Optional[List[str]] = None,
decode: Literal[True] = True
) -> Nvim:
"""Provide a nicer interface to create python api sessions.
Expand Down
12 changes: 6 additions & 6 deletions pynvim/api/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@overload
def adjust_index(idx: int, default: int = None) -> int:
def adjust_index(idx: int, default: Optional[int] = None) -> int:
...


Expand All @@ -23,11 +23,11 @@ def adjust_index(idx: Optional[int], default: int) -> int:


@overload
def adjust_index(idx: Optional[int], default: int = None) -> Optional[int]:
def adjust_index(idx: Optional[int], default: Optional[int] = None) -> Optional[int]:
...


def adjust_index(idx: Optional[int], default: int = None) -> Optional[int]:
def adjust_index(idx: Optional[int], default: Optional[int] = None) -> Optional[int]:
"""Convert from python indexing convention to nvim indexing convention."""
if idx is None:
return default
Expand Down Expand Up @@ -161,7 +161,7 @@ def add_highlight(
col_start: int = 0,
col_end: int = -1,
src_id: int = -1,
async_: bool = None,
async_: Optional[bool] = None,
**kwargs: Any
) -> int:
"""Add a highlight to the buffer."""
Expand All @@ -181,7 +181,7 @@ def clear_highlight(
src_id: int,
line_start: int = 0,
line_end: int = -1,
async_: bool = None,
async_: Optional[bool] = None,
**kwargs: Any
) -> None:
"""Clear highlights from the buffer."""
Expand Down Expand Up @@ -301,7 +301,7 @@ def __iter__(self) -> Iterator[str]:
yield self._buffer[i]

def append(
self, lines: Union[str, bytes, List[Union[str, bytes]]], i: int = None
self, lines: Union[str, bytes, List[Union[str, bytes]]], i: Optional[int] = None
) -> None:
i = self._normalize_index(i)
if i is None:
Expand Down
4 changes: 2 additions & 2 deletions pynvim/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def __init__(
self,
obj: IRemote,
get_method: str,
set_method: str = None,
del_method: str = None
set_method: Optional[str] = None,
del_method: Optional[str] = None
):
"""Initialize a RemoteMap with session, getter/setter."""
self._get = functools.partial(obj.request, get_method)
Expand Down
10 changes: 5 additions & 5 deletions pynvim/api/nvim.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(
metadata: Dict[str, Any],
types: Dict[int, Any],
decode: TDecodeMode = True,
err_cb: Callable[[str], None] = None
err_cb: Optional[Callable[[str], None]] = None
):
"""Initialize a new Nvim instance. This method is module-private."""
self._session = session
Expand Down Expand Up @@ -142,7 +142,7 @@ def __init__(
self._err_cb = err_cb
self.loop = self._session.loop._loop

def _from_nvim(self, obj: Any, decode: TDecodeMode = None) -> Any:
def _from_nvim(self, obj: Any, decode: Optional[TDecodeMode] = None) -> Any:
if decode is None:
decode = self._decode
if type(obj) is ExtType:
Expand Down Expand Up @@ -213,8 +213,8 @@ def run_loop(
self,
request_cb: Optional[Callable[[str, List[Any]], Any]],
notification_cb: Optional[Callable[[str, List[Any]], Any]],
setup_cb: Callable[[], None] = None,
err_cb: Callable[[str], Any] = None
setup_cb: Optional[Callable[[], None]] = None,
err_cb: Optional[Callable[[str], Any]] = None
) -> None:
"""Run the event loop to receive requests and notifications from Nvim.
Expand Down Expand Up @@ -275,7 +275,7 @@ def with_decode(self, decode: Literal[True] = True) -> 'Nvim':
self.metadata, self.types, decode, self._err_cb)

def ui_attach(
self, width: int, height: int, rgb: bool = None, **kwargs: Any
self, width: int, height: int, rgb: Optional[bool] = None, **kwargs: Any
) -> None:
"""Register as a remote UI.
Expand Down
2 changes: 1 addition & 1 deletion pynvim/msgpack_rpc/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def request(self, method: AnyStr, *args: Any, **kwargs: Any) -> Any:
def run(self,
request_cb: Callable[[str, List[Any]], None],
notification_cb: Callable[[str, List[Any]], None],
setup_cb: Callable[[], None] = None) -> None:
setup_cb: Optional[Callable[[], None]] = None) -> None:
"""Run the event loop to receive requests and notifications from Nvim.
Like `AsyncSession.run()`, but `request_cb` and `notification_cb` are
Expand Down
14 changes: 7 additions & 7 deletions pynvim/plugin/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import inspect
import logging
import sys
from typing import Any, Callable, Dict, TypeVar, Union
from typing import Any, Callable, Dict, Optional, TypeVar, Union

from pynvim.compat import unicode_errors_default

Expand Down Expand Up @@ -52,14 +52,14 @@ def dec(f: F) -> F:
def command(
name: str,
nargs: Union[str, int] = 0,
complete: str = None,
range: Union[str, int] = None,
count: int = None,
complete: Optional[str] = None,
range: Optional[Union[str, int]] = None,
count: Optional[int] = None,
bang: bool = False,
register: bool = False,
sync: bool = False,
allow_nested: bool = False,
eval: str = None
eval: Optional[str] = None
) -> Callable[[F], F]:
"""Tag a function or plugin method as a Nvim command handler."""
def dec(f: F) -> F:
Expand Down Expand Up @@ -112,7 +112,7 @@ def autocmd(
pattern: str = '*',
sync: bool = False,
allow_nested: bool = False,
eval: str = None
eval: Optional[str] = None
) -> Callable[[F], F]:
"""Tag a function or plugin method as a Nvim autocommand handler."""
def dec(f: F) -> F:
Expand Down Expand Up @@ -150,7 +150,7 @@ def function(
range: Union[bool, str, int] = False,
sync: bool = False,
allow_nested: bool = False,
eval: str = None
eval: Optional[str] = None
) -> Callable[[F], F]:
"""Tag a function or plugin method as a Nvim function handler."""
def dec(f: F) -> F:
Expand Down
4 changes: 2 additions & 2 deletions pynvim/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import sys
from traceback import format_exception
from types import SimpleNamespace
from typing import Any, Dict, Tuple, TypeVar
from typing import Any, Dict, Optional, Tuple, TypeVar


def format_exc_skip(skip: int, limit: int = None) -> str:
def format_exc_skip(skip: int, limit: Optional[int] = None) -> str:
"""Like traceback.format_exc but allow skipping the first frames."""
etype, val, tb = sys.exc_info()
for _ in range(skip):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test = pytest

[flake8]
extend-ignore = D211,E731,D401,W503
max-line-length = 88
max-line-length = 100
per-file-ignores =
test/*:D1
application-import-names = pynvim
Expand Down

0 comments on commit 991c689

Please sign in to comment.