Skip to content

Commit 9d9455c

Browse files
committed
add flake8 and mypy settings
1 parent 6efee94 commit 9d9455c

File tree

12 files changed

+122
-78
lines changed

12 files changed

+122
-78
lines changed

.pre-commit-config.yaml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,27 @@ repos:
4848
- id: doc8
4949
args: [--max-line-length=200]
5050

51-
# - repo: https://github.com/pycqa/flake8
52-
# rev: 4.0.1
53-
# hooks:
54-
# - id: flake8
55-
# additional_dependencies:
56-
# [
57-
# "flake8-bugbear==20.1.4",
58-
# "flake8-logging-format==0.6.0",
59-
# "flake8-implicit-str-concat==0.2.0",
60-
# ]
51+
- repo: https://github.com/pycqa/flake8
52+
rev: 4.0.1
53+
hooks:
54+
- id: flake8
55+
additional_dependencies:
56+
[
57+
"flake8-bugbear==20.1.4",
58+
"flake8-logging-format==0.6.0",
59+
"flake8-implicit-str-concat==0.2.0",
60+
]
6161

62-
# - repo: https://github.com/pre-commit/mirrors-mypy
63-
# rev: v0.942
64-
# hooks:
65-
# - id: mypy
62+
- repo: https://github.com/pre-commit/mirrors-mypy
63+
rev: v0.942
64+
hooks:
65+
- id: mypy
66+
exclude: |
67+
exclude: |
68+
(?x)^(
69+
jupyter_core/tests/.*_config.py |
70+
scripts/jupyter
71+
)$
6672
6773
- repo: https://github.com/sirosen/check-jsonschema
6874
rev: 0.14.2

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include COPYING.md
22
include CONTRIBUTING.md
33
include README.md
44
include dev-requirements.txt
5+
include jupyter_core/py.typed
56

67
exclude .pre-commit-config.yaml
78
exclude .git-blame-ignore-revs

docs/conf.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,7 @@
208208

209209
# -- Options for LaTeX output ---------------------------------------------
210210

211-
latex_elements = {
212-
# The paper size ('letterpaper' or 'a4paper').
213-
#'papersize': 'letterpaper',
214-
# The font size ('10pt', '11pt' or '12pt').
215-
#'pointsize': '10pt',
216-
# Additional stuff for the LaTeX preamble.
217-
#'preamble': '',
218-
# Latex figure (float) alignment
219-
#'figure_align': 'htbp',
220-
}
211+
latex_elements: dict = {}
221212

222213
# Grouping the document tree into LaTeX files. List of tuples
223214
# (source start file, target name, title,

jupyter_core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .version import __version__, version_info
1+
from .version import __version__, version_info # noqa

jupyter_core/command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class JupyterParser(argparse.ArgumentParser):
24-
@property
24+
@property # type:ignore[override]
2525
def epilog(self):
2626
"""Add subcommands to epilog on request
2727
@@ -30,7 +30,7 @@ def epilog(self):
3030
return "Available subcommands: %s" % " ".join(list_subcommands())
3131

3232
@epilog.setter
33-
def epilog(self, x):
33+
def epilog(self):
3434
"""Ignore epilog set in Parser.__init__"""
3535
pass
3636

jupyter_core/paths.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import warnings
1818
from contextlib import contextmanager
1919
from pathlib import Path
20+
from typing import Optional
2021

2122
pjoin = os.path.join
2223

@@ -43,7 +44,7 @@ def get_home_dir():
4344
return homedir
4445

4546

46-
_dtemps = {}
47+
_dtemps: dict = {}
4748

4849

4950
def _mkdtemp_once(name):
@@ -159,7 +160,7 @@ def jupyter_path(*subdirs):
159160
['~/.local/jupyter/kernels', '/usr/local/share/jupyter/kernels']
160161
"""
161162

162-
paths = []
163+
paths: list = []
163164

164165
# highest priority is explicit environment variable
165166
if os.environ.get("JUPYTER_PATH"):
@@ -170,13 +171,16 @@ def jupyter_path(*subdirs):
170171
if site.ENABLE_USER_SITE:
171172
# Check if site.getuserbase() exists to be compatible with virtualenv,
172173
# which often does not have this method.
174+
userbase: Optional[str]
173175
if hasattr(site, "getuserbase"):
174176
userbase = site.getuserbase()
175177
else:
176178
userbase = site.USER_BASE
177-
userdir = os.path.join(userbase, "share", "jupyter")
178-
if userdir not in user:
179-
user.append(userdir)
179+
180+
if userbase:
181+
userdir = os.path.join(userbase, "share", "jupyter")
182+
if userdir not in user:
183+
user.append(userdir)
180184

181185
env = [p for p in ENV_JUPYTER_PATH if p not in SYSTEM_JUPYTER_PATH]
182186

@@ -225,7 +229,7 @@ def jupyter_config_path():
225229
# jupyter_config_dir makes a blank config when JUPYTER_NO_CONFIG is set.
226230
return [jupyter_config_dir()]
227231

228-
paths = []
232+
paths: list = []
229233

230234
# highest priority is explicit environment variable
231235
if os.environ.get("JUPYTER_CONFIG_PATH"):
@@ -234,16 +238,18 @@ def jupyter_config_path():
234238
# Next is environment or user, depending on the JUPYTER_PREFER_ENV_PATH flag
235239
user = [jupyter_config_dir()]
236240
if site.ENABLE_USER_SITE:
241+
userbase: Optional[str]
237242
# Check if site.getuserbase() exists to be compatible with virtualenv,
238243
# which often does not have this method.
239244
if hasattr(site, "getuserbase"):
240245
userbase = site.getuserbase()
241246
else:
242247
userbase = site.USER_BASE
243248

244-
userdir = os.path.join(userbase, "etc", "jupyter")
245-
if userdir not in user:
246-
user.append(userdir)
249+
if userbase:
250+
userdir = os.path.join(userbase, "etc", "jupyter")
251+
if userdir not in user:
252+
user.append(userdir)
247253

248254
env = [p for p in ENV_CONFIG_PATH if p not in SYSTEM_CONFIG_PATH]
249255

@@ -298,7 +304,7 @@ def is_file_hidden_win(abs_path, stat_res=None):
298304
raise
299305

300306
try:
301-
if stat_res.st_file_attributes & stat.FILE_ATTRIBUTE_HIDDEN:
307+
if stat_res.st_file_attributes & stat.FILE_ATTRIBUTE_HIDDEN: # type:ignore[attr-defined]
302308
return True
303309
except AttributeError:
304310
# allow AttributeError on PyPy for Windows
@@ -470,8 +476,8 @@ def _win32_restrict_file_to_user_ctypes(fname):
470476
import ctypes
471477
from ctypes import wintypes
472478

473-
advapi32 = ctypes.WinDLL("advapi32", use_last_error=True)
474-
secur32 = ctypes.WinDLL("secur32", use_last_error=True)
479+
advapi32 = ctypes.WinDLL("advapi32", use_last_error=True) # type:ignore[attr-defined]
480+
secur32 = ctypes.WinDLL("secur32", use_last_error=True) # type:ignore[attr-defined]
475481

476482
NameSamCompatible = 2
477483
WinBuiltinAdministratorsSid = 26
@@ -520,7 +526,7 @@ class ACL(ctypes.Structure):
520526

521527
def _nonzero_success(result, func, args):
522528
if not result:
523-
raise ctypes.WinError(ctypes.get_last_error())
529+
raise ctypes.WinError(ctypes.get_last_error()) # type:ignore[attr-defined]
524530
return args
525531

526532
secur32.GetUserNameExW.errcheck = _nonzero_success
@@ -627,7 +633,7 @@ def CreateWellKnownSid(WellKnownSidType):
627633
try:
628634
advapi32.CreateWellKnownSid(WellKnownSidType, None, pSid, ctypes.byref(cbSid))
629635
except OSError as e:
630-
if e.winerror != ERROR_INSUFFICIENT_BUFFER:
636+
if e.winerror != ERROR_INSUFFICIENT_BUFFER: # type:ignore[attr-defined]
631637
raise
632638
pSid = (ctypes.c_char * cbSid.value)()
633639
advapi32.CreateWellKnownSid(WellKnownSidType, None, pSid, ctypes.byref(cbSid))
@@ -640,7 +646,7 @@ def GetUserNameEx(NameFormat):
640646
try:
641647
secur32.GetUserNameExW(NameFormat, None, nSize)
642648
except OSError as e:
643-
if e.winerror != ERROR_MORE_DATA:
649+
if e.winerror != ERROR_MORE_DATA: # type:ignore[attr-defined]
644650
raise
645651
if not nSize.contents.value:
646652
return None
@@ -665,7 +671,7 @@ def LookupAccountName(lpSystemName, lpAccountName):
665671
ctypes.byref(peUse),
666672
)
667673
except OSError as e:
668-
if e.winerror != ERROR_INSUFFICIENT_BUFFER:
674+
if e.winerror != ERROR_INSUFFICIENT_BUFFER: # type:ignore[attr-defined]
669675
raise
670676
Sid = ctypes.create_unicode_buffer("", cbSid.value)
671677
pSid = ctypes.cast(ctypes.pointer(Sid), wintypes.LPVOID)
@@ -680,7 +686,7 @@ def LookupAccountName(lpSystemName, lpAccountName):
680686
ctypes.byref(peUse),
681687
)
682688
if not success:
683-
raise ctypes.WinError()
689+
raise ctypes.WinError() # type:ignore[attr-defined]
684690
return pSid, lpReferencedDomainName.value, peUse.value
685691

686692
def AddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid):
@@ -700,7 +706,7 @@ def GetFileSecurity(lpFileName, RequestedInformation):
700706
ctypes.byref(nLength),
701707
)
702708
except OSError as e:
703-
if e.winerror != ERROR_INSUFFICIENT_BUFFER:
709+
if e.winerror != ERROR_INSUFFICIENT_BUFFER: # type:ignore[attr-defined]
704710
raise
705711
if not nLength.value:
706712
return None
@@ -750,7 +756,7 @@ def MakeAbsoluteSD(pSelfRelativeSecurityDescriptor):
750756
ctypes.byref(lpdwPrimaryGroupSize),
751757
)
752758
except OSError as e:
753-
if e.winerror != ERROR_INSUFFICIENT_BUFFER:
759+
if e.winerror != ERROR_INSUFFICIENT_BUFFER: # type:ignore[attr-defined]
754760
raise
755761
pAbsoluteSecurityDescriptor = (wintypes.BYTE * lpdwAbsoluteSecurityDescriptorSize.value)()
756762
pDaclData = (wintypes.BYTE * lpdwDaclSize.value)()
@@ -788,7 +794,7 @@ def MakeSelfRelativeSD(pAbsoluteSecurityDescriptor):
788794
ctypes.byref(lpdwBufferLength),
789795
)
790796
except OSError as e:
791-
if e.winerror != ERROR_INSUFFICIENT_BUFFER:
797+
if e.winerror != ERROR_INSUFFICIENT_BUFFER: # type:ignore[attr-defined]
792798
raise
793799
pSelfRelativeSecurityDescriptor = (wintypes.BYTE * lpdwBufferLength.value)()
794800
advapi32.MakeSelfRelativeSD(
@@ -907,7 +913,7 @@ def issue_insecure_write_warning():
907913
def format_warning(msg, *args, **kwargs):
908914
return str(msg) + "\n"
909915

910-
warnings.formatwarning = format_warning
916+
warnings.formatwarning = format_warning # type:ignore[assignment]
911917
warnings.warn(
912918
"WARNING: Insecure writes have been enabled via environment variable "
913919
"'JUPYTER_ALLOW_INSECURE_WRITES'! If this is not intended, remove the "

jupyter_core/py.typed

Whitespace-only changes.

jupyter_core/tests/test_command.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import pytest
1111

12-
from jupyter_core import __version__
1312
from jupyter_core.command import list_subcommands
1413
from jupyter_core.paths import (
1514
jupyter_config_dir,
@@ -95,7 +94,7 @@ def test_paths_json():
9594
output = get_jupyter_output(["--paths", "--json"])
9695
data = json.loads(output)
9796
assert sorted(data) == ["config", "data", "runtime"]
98-
for key, path in data.items():
97+
for _, path in data.items():
9998
assert isinstance(path, list)
10099

101100

jupyter_core/tests/test_paths.py

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

1919
from jupyter_core import paths
2020
from jupyter_core.paths import (
21-
ENV_JUPYTER_PATH,
2221
is_file_hidden,
2322
is_hidden,
2423
jupyter_config_dir,
@@ -148,12 +147,12 @@ def test_data_dir_darwin():
148147
@pytest.mark.skipif(sys.platform != "win32", reason="only run on windows")
149148
def test_data_dir_windows():
150149
data = jupyter_data_dir()
151-
assert data == realpath(pjoin(os.environ.get("APPDATA", None), "jupyter"))
150+
assert data == realpath(pjoin(os.environ.get("APPDATA", ""), "jupyter"))
152151

153152
with xdg:
154153
# windows should ignore xdg
155154
data = jupyter_data_dir()
156-
assert data == realpath(pjoin(os.environ.get("APPDATA", None), "jupyter"))
155+
assert data == realpath(pjoin(os.environ.get("APPDATA", ""), "jupyter"))
157156

158157

159158
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
@@ -189,12 +188,12 @@ def test_runtime_dir_darwin():
189188
@pytest.mark.skipif(sys.platform != "win32", reason="only run on windows")
190189
def test_runtime_dir_windows():
191190
runtime = jupyter_runtime_dir()
192-
assert runtime == realpath(pjoin(os.environ.get("APPDATA", None), "jupyter", "runtime"))
191+
assert runtime == realpath(pjoin(os.environ.get("APPDATA", ""), "jupyter", "runtime"))
193192

194193
with xdg:
195194
# windows should ignore xdg
196195
runtime = jupyter_runtime_dir()
197-
assert runtime == realpath(pjoin(os.environ.get("APPDATA", None), "jupyter", "runtime"))
196+
assert runtime == realpath(pjoin(os.environ.get("APPDATA", ""), "jupyter", "runtime"))
198197

199198

200199
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
@@ -364,7 +363,7 @@ def test_is_hidden():
364363
reason="only run on windows/cpython or pypy >= 7.3.6: https://foss.heptapod.net/pypy/pypy/-/issues/3469",
365364
)
366365
def test_is_hidden_win32_cpython():
367-
import ctypes
366+
import ctypes # noqa
368367

369368
with tempfile.TemporaryDirectory() as root:
370369
subdir1 = os.path.join(root, "subdir")
@@ -384,7 +383,7 @@ def test_is_hidden_win32_cpython():
384383
reason="only run on windows/pypy < 7.3.6: https://foss.heptapod.net/pypy/pypy/-/issues/3469",
385384
)
386385
def test_is_hidden_win32_pypy():
387-
import ctypes
386+
import ctypes # noqa
388387

389388
with tempfile.TemporaryDirectory() as root:
390389
subdir1 = os.path.join(root, "subdir")

0 commit comments

Comments
 (0)