Skip to content

Commit 991c689

Browse files
committed
fix: PEP 484 prohibits implicit Optional
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
1 parent 919217d commit 991c689

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

pynvim/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
import sys
88
from types import SimpleNamespace as Version
9-
from typing import List, cast, overload
9+
from typing import List, Optional, cast, overload
1010

1111
from pynvim.api import Nvim, NvimError
1212
from pynvim.msgpack_rpc import (ErrorResponse, Session, TTransportType, child_session,
@@ -28,7 +28,7 @@
2828
'ErrorResponse')
2929

3030

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

102102
def attach(
103103
session_type: TTransportType,
104-
address: str = None,
104+
address: Optional[str] = None,
105105
port: int = 7450,
106-
path: str = None,
107-
argv: List[str] = None,
106+
path: Optional[str] = None,
107+
argv: Optional[List[str]] = None,
108108
decode: Literal[True] = True
109109
) -> Nvim:
110110
"""Provide a nicer interface to create python api sessions.

pynvim/api/buffer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
@overload
16-
def adjust_index(idx: int, default: int = None) -> int:
16+
def adjust_index(idx: int, default: Optional[int] = None) -> int:
1717
...
1818

1919

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

2424

2525
@overload
26-
def adjust_index(idx: Optional[int], default: int = None) -> Optional[int]:
26+
def adjust_index(idx: Optional[int], default: Optional[int] = None) -> Optional[int]:
2727
...
2828

2929

30-
def adjust_index(idx: Optional[int], default: int = None) -> Optional[int]:
30+
def adjust_index(idx: Optional[int], default: Optional[int] = None) -> Optional[int]:
3131
"""Convert from python indexing convention to nvim indexing convention."""
3232
if idx is None:
3333
return default
@@ -161,7 +161,7 @@ def add_highlight(
161161
col_start: int = 0,
162162
col_end: int = -1,
163163
src_id: int = -1,
164-
async_: bool = None,
164+
async_: Optional[bool] = None,
165165
**kwargs: Any
166166
) -> int:
167167
"""Add a highlight to the buffer."""
@@ -181,7 +181,7 @@ def clear_highlight(
181181
src_id: int,
182182
line_start: int = 0,
183183
line_end: int = -1,
184-
async_: bool = None,
184+
async_: Optional[bool] = None,
185185
**kwargs: Any
186186
) -> None:
187187
"""Clear highlights from the buffer."""
@@ -301,7 +301,7 @@ def __iter__(self) -> Iterator[str]:
301301
yield self._buffer[i]
302302

303303
def append(
304-
self, lines: Union[str, bytes, List[Union[str, bytes]]], i: int = None
304+
self, lines: Union[str, bytes, List[Union[str, bytes]]], i: Optional[int] = None
305305
) -> None:
306306
i = self._normalize_index(i)
307307
if i is None:

pynvim/api/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def __init__(
123123
self,
124124
obj: IRemote,
125125
get_method: str,
126-
set_method: str = None,
127-
del_method: str = None
126+
set_method: Optional[str] = None,
127+
del_method: Optional[str] = None
128128
):
129129
"""Initialize a RemoteMap with session, getter/setter."""
130130
self._get = functools.partial(obj.request, get_method)

pynvim/api/nvim.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __init__(
112112
metadata: Dict[str, Any],
113113
types: Dict[int, Any],
114114
decode: TDecodeMode = True,
115-
err_cb: Callable[[str], None] = None
115+
err_cb: Optional[Callable[[str], None]] = None
116116
):
117117
"""Initialize a new Nvim instance. This method is module-private."""
118118
self._session = session
@@ -142,7 +142,7 @@ def __init__(
142142
self._err_cb = err_cb
143143
self.loop = self._session.loop._loop
144144

145-
def _from_nvim(self, obj: Any, decode: TDecodeMode = None) -> Any:
145+
def _from_nvim(self, obj: Any, decode: Optional[TDecodeMode] = None) -> Any:
146146
if decode is None:
147147
decode = self._decode
148148
if type(obj) is ExtType:
@@ -213,8 +213,8 @@ def run_loop(
213213
self,
214214
request_cb: Optional[Callable[[str, List[Any]], Any]],
215215
notification_cb: Optional[Callable[[str, List[Any]], Any]],
216-
setup_cb: Callable[[], None] = None,
217-
err_cb: Callable[[str], Any] = None
216+
setup_cb: Optional[Callable[[], None]] = None,
217+
err_cb: Optional[Callable[[str], Any]] = None
218218
) -> None:
219219
"""Run the event loop to receive requests and notifications from Nvim.
220220
@@ -275,7 +275,7 @@ def with_decode(self, decode: Literal[True] = True) -> 'Nvim':
275275
self.metadata, self.types, decode, self._err_cb)
276276

277277
def ui_attach(
278-
self, width: int, height: int, rgb: bool = None, **kwargs: Any
278+
self, width: int, height: int, rgb: Optional[bool] = None, **kwargs: Any
279279
) -> None:
280280
"""Register as a remote UI.
281281

pynvim/msgpack_rpc/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def request(self, method: AnyStr, *args: Any, **kwargs: Any) -> Any:
140140
def run(self,
141141
request_cb: Callable[[str, List[Any]], None],
142142
notification_cb: Callable[[str, List[Any]], None],
143-
setup_cb: Callable[[], None] = None) -> None:
143+
setup_cb: Optional[Callable[[], None]] = None) -> None:
144144
"""Run the event loop to receive requests and notifications from Nvim.
145145
146146
Like `AsyncSession.run()`, but `request_cb` and `notification_cb` are

pynvim/plugin/decorators.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import inspect
44
import logging
55
import sys
6-
from typing import Any, Callable, Dict, TypeVar, Union
6+
from typing import Any, Callable, Dict, Optional, TypeVar, Union
77

88
from pynvim.compat import unicode_errors_default
99

@@ -52,14 +52,14 @@ def dec(f: F) -> F:
5252
def command(
5353
name: str,
5454
nargs: Union[str, int] = 0,
55-
complete: str = None,
56-
range: Union[str, int] = None,
57-
count: int = None,
55+
complete: Optional[str] = None,
56+
range: Optional[Union[str, int]] = None,
57+
count: Optional[int] = None,
5858
bang: bool = False,
5959
register: bool = False,
6060
sync: bool = False,
6161
allow_nested: bool = False,
62-
eval: str = None
62+
eval: Optional[str] = None
6363
) -> Callable[[F], F]:
6464
"""Tag a function or plugin method as a Nvim command handler."""
6565
def dec(f: F) -> F:
@@ -112,7 +112,7 @@ def autocmd(
112112
pattern: str = '*',
113113
sync: bool = False,
114114
allow_nested: bool = False,
115-
eval: str = None
115+
eval: Optional[str] = None
116116
) -> Callable[[F], F]:
117117
"""Tag a function or plugin method as a Nvim autocommand handler."""
118118
def dec(f: F) -> F:
@@ -150,7 +150,7 @@ def function(
150150
range: Union[bool, str, int] = False,
151151
sync: bool = False,
152152
allow_nested: bool = False,
153-
eval: str = None
153+
eval: Optional[str] = None
154154
) -> Callable[[F], F]:
155155
"""Tag a function or plugin method as a Nvim function handler."""
156156
def dec(f: F) -> F:

pynvim/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import sys
44
from traceback import format_exception
55
from types import SimpleNamespace
6-
from typing import Any, Dict, Tuple, TypeVar
6+
from typing import Any, Dict, Optional, Tuple, TypeVar
77

88

9-
def format_exc_skip(skip: int, limit: int = None) -> str:
9+
def format_exc_skip(skip: int, limit: Optional[int] = None) -> str:
1010
"""Like traceback.format_exc but allow skipping the first frames."""
1111
etype, val, tb = sys.exc_info()
1212
for _ in range(skip):

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ test = pytest
33

44
[flake8]
55
extend-ignore = D211,E731,D401,W503
6-
max-line-length = 88
6+
max-line-length = 100
77
per-file-ignores =
88
test/*:D1
99
application-import-names = pynvim

0 commit comments

Comments
 (0)