Skip to content

Commit 6e36b34

Browse files
committed
add conftest and improve type-hints
1 parent bc10fd9 commit 6e36b34

7 files changed

Lines changed: 43 additions & 6 deletions

File tree

template/commands/sys_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .. import sys_info
44

55

6-
def run():
6+
def run() -> None:
77
"""Run sys_info() command."""
88
parser = argparse.ArgumentParser(
99
prog=f"{__package__.split('.')[0]}-sys_info", description="sys_info"

template/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from __future__ import annotations # c.f. PEP 563, PEP 649
2+
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from pytest import Config
7+
8+
9+
def pytest_configure(config: Config) -> None:
10+
"""Configure pytest options."""
11+
warnings_lines = r"""
12+
error::
13+
"""
14+
for warning_line in warnings_lines.split("\n"):
15+
warning_line = warning_line.strip()
16+
if warning_line and not warning_line.startswith("#"):
17+
config.addinivalue_line("filterwarnings", warning_line)

template/utils/_checks.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
"""Utility functions for checking types and values. Inspired from MNE."""
22

3+
from __future__ import annotations # c.f. PEP 563, PEP 649
4+
35
import logging
46
import operator
57
import os
68
from pathlib import Path
7-
from typing import Any, Optional
9+
from typing import TYPE_CHECKING
810

911
import numpy as np
1012

1113
from ._docs import fill_doc
1214

15+
if TYPE_CHECKING:
16+
from typing import Any, Optional
17+
1318

1419
def ensure_int(item: Any, item_name: Optional[str] = None) -> int:
1520
"""Ensure a variable is an integer.

template/utils/_docs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
Inspired from mne.utils.docs.py by Eric Larson <larson.eric.d@gmail.com>
55
"""
66

7+
from __future__ import annotations # c.f. PEP 563, PEP 649
8+
79
import sys
8-
from typing import Callable, Dict, List
10+
from typing import TYPE_CHECKING
11+
12+
if TYPE_CHECKING:
13+
from typing import Callable, Dict, List
914

1015
# ------------------------- Documentation dictionary -------------------------
1116
docdict: Dict[str, str] = dict()

template/utils/_fixes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class WrapStdOut(object):
1111
properly.
1212
"""
1313

14-
def __getattr__(self, name): # noqa: D105
14+
def __getattr__(self, name: str): # noqa: D105
1515
# Even more ridiculous than this class, this must be sys.stdout (not
1616
# just stdout) in order for this to work (tested on OSX and Linux).
1717
if hasattr(sys.stdout, name):

template/utils/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
from __future__ import annotations # c.f. PEP 563, PEP 649
2+
13
import platform
24
import sys
35
from functools import partial
46
from importlib.metadata import requires, version
5-
from typing import IO, Callable, List, Optional
7+
from typing import TYPE_CHECKING
68

79
import psutil
810
from packaging.requirements import Requirement
911

1012
from ._checks import check_type
1113

14+
if TYPE_CHECKING:
15+
from typing import IO, Callable, List, Optional
16+
1217

1318
def sys_info(fid: Optional[IO] = None, developer: bool = False):
1419
"""Print the system information for debugging.

template/utils/logs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
from __future__ import annotations # c.f. PEP 563, PEP 649
2+
13
import logging
24
from functools import wraps
35
from pathlib import Path
4-
from typing import Callable, Optional, Union
6+
from typing import TYPE_CHECKING
57

68
from ._checks import check_verbose
79
from ._docs import fill_doc
810
from ._fixes import WrapStdOut
911

12+
if TYPE_CHECKING:
13+
from typing import Callable, Optional, Union
14+
1015

1116
@fill_doc
1217
def _init_logger(*, verbose: Optional[Union[bool, str, int]] = None) -> logging.Logger:

0 commit comments

Comments
 (0)