Skip to content

Commit ccf17dd

Browse files
committed
fix(mypy): fix type errs
1 parent d857eeb commit ccf17dd

File tree

7 files changed

+48
-39
lines changed

7 files changed

+48
-39
lines changed

sphinx_autodoc_vyper/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .server import serve_docs
1010

1111

12-
def main():
12+
def main() -> None:
1313
"""Main entry point for the CLI."""
1414
parser = argparse.ArgumentParser(
1515
description="Generate Sphinx documentation for Vyper contracts"

sphinx_autodoc_vyper/generator.py

+30-25
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@
55
from .parser import Contract
66

77

8-
class SphinxGenerator:
9-
"""Generate Sphinx documentation for Vyper contracts."""
8+
INDEX_RST = """Vyper Smart Contracts Documentation
9+
================================
1010
11-
def __init__(self, output_dir: str):
12-
self.output_dir = output_dir
13-
self.docs_dir = os.path.join(output_dir, "docs")
14-
os.makedirs(self.docs_dir, exist_ok=True)
11+
.. toctree::
12+
:maxdepth: 2
13+
:caption: Contents:
1514
16-
def generate(self, contracts: List[Contract]):
17-
"""Generate Sphinx documentation."""
18-
self._generate_conf_py()
19-
self._generate_index_rst(contracts)
20-
self._generate_contract_docs(contracts)
15+
"""
2116

22-
def _generate_conf_py(self):
23-
"""Generate Sphinx configuration file."""
24-
conf_content = """# Configuration file for Sphinx documentation
17+
18+
CONF_CONTENT = """# Configuration file for Sphinx documentation
2519
2620
project = 'Vyper Smart Contracts'
2721
copyright = '2023'
@@ -39,26 +33,37 @@ def _generate_conf_py(self):
3933
html_theme = 'sphinx_rtd_theme'
4034
html_static_path = ['_static']
4135
"""
42-
with open(os.path.join(self.docs_dir, "conf.py"), "w", encoding="utf-8") as f:
43-
f.write(conf_content)
4436

45-
def _generate_index_rst(self, contracts: List[Contract]):
46-
"""Generate index.rst file."""
47-
content = """Vyper Smart Contracts Documentation
48-
================================
4937

50-
.. toctree::
51-
:maxdepth: 2
52-
:caption: Contents:
38+
class SphinxGenerator:
39+
"""Generate Sphinx documentation for Vyper contracts."""
5340

54-
"""
41+
def __init__(self, output_dir: str):
42+
self.output_dir = output_dir
43+
self.docs_dir = os.path.join(output_dir, "docs")
44+
os.makedirs(self.docs_dir, exist_ok=True)
45+
46+
def generate(self, contracts: List[Contract]) -> None:
47+
"""Generate Sphinx documentation."""
48+
self._generate_conf_py()
49+
self._generate_index_rst(contracts)
50+
self._generate_contract_docs(contracts)
51+
52+
def _generate_conf_py(self) -> None:
53+
"""Generate Sphinx configuration file."""
54+
with open(os.path.join(self.docs_dir, "conf.py"), "w", encoding="utf-8") as f:
55+
f.write(CONF_CONTENT)
56+
57+
def _generate_index_rst(self, contracts: List[Contract]) -> None:
58+
"""Generate index.rst file."""
59+
content = INDEX_RST
5560
for contract in contracts:
5661
content += f" {contract.name}\n"
5762

5863
with open(os.path.join(self.docs_dir, "index.rst"), "w", encoding="utf-8") as f:
5964
f.write(content)
6065

61-
def _generate_contract_docs(self, contracts: List[Contract]):
66+
def _generate_contract_docs(self, contracts: List[Contract]) -> None:
6267
"""Generate documentation for each contract."""
6368
for contract in contracts:
6469
content = f"""{contract.name}

sphinx_autodoc_vyper/server.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import os
66
import webbrowser
77
from pathlib import Path
8+
from typing import NoReturn
89

910

10-
def serve_docs(port: int = 8000):
11+
def serve_docs(port: int = 8000) -> NoReturn:
1112
"""Serve the documentation on a local development server."""
1213
build_dir = Path("docs/_build/html")
1314

tests/conftest.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@pytest.fixture
9-
def sample_contract():
9+
def sample_contract() -> str:
1010
"""Sample Vyper contract content."""
1111
return '''"""
1212
ERC20 Token Implementation
@@ -43,7 +43,7 @@ def balance_of(account: address) -> uint256:
4343

4444

4545
@pytest.fixture
46-
def contracts_dir(tmp_path, sample_contract):
46+
def contracts_dir(tmp_path: Path, sample_contract: str) -> Path:
4747
"""Create a temporary directory with sample contracts."""
4848
contracts = tmp_path / "contracts"
4949
contracts.mkdir()
@@ -62,7 +62,7 @@ def contracts_dir(tmp_path, sample_contract):
6262

6363

6464
@pytest.fixture
65-
def output_dir(tmp_path):
65+
def output_dir(tmp_path: Path) -> Path:
6666
"""Create a temporary output directory."""
6767
output = tmp_path / "output"
6868
output.mkdir()

tests/test_generator.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import os
44
import pytest
5+
from pathlib import Path
56
from sphinx_autodoc_vyper.generator import SphinxGenerator
67
from sphinx_autodoc_vyper.parser import VyperParser
78

89

9-
def test_sphinx_generation(contracts_dir, output_dir):
10+
def test_sphinx_generation(contracts_dir: Path, output_dir: Path) -> None:
1011
"""Test complete Sphinx documentation generation."""
1112
# Parse contracts
1213
parser = VyperParser(str(contracts_dir))
@@ -44,7 +45,7 @@ def test_sphinx_generation(contracts_dir, output_dir):
4445
assert "balance_of" in token_content
4546

4647

47-
def test_contract_rst_generation(contracts_dir, output_dir):
48+
def test_contract_rst_generation(contracts_dir: Path, output_dir: Path) -> None:
4849
"""Test detailed RST file generation for contracts."""
4950
parser = VyperParser(str(contracts_dir))
5051
contracts = parser.parse_contracts()

tests/test_parser.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Tests for the Vyper contract parser."""
22

33
import pytest
4+
from pathlib import Path
45
from sphinx_autodoc_vyper.parser import VyperParser, Contract, Function, Parameter
56

67

7-
def test_parse_contracts(contracts_dir):
8+
def test_parse_contracts(contracts_dir: Path) -> None:
89
"""Test parsing multiple contracts."""
910
parser = VyperParser(str(contracts_dir))
1011
contracts = parser.parse_contracts()
@@ -14,7 +15,7 @@ def test_parse_contracts(contracts_dir):
1415
assert any(c.name == "nested_token" for c in contracts)
1516

1617

17-
def test_contract_parsing(contracts_dir):
18+
def test_contract_parsing(contracts_dir: Path) -> None:
1819
"""Test detailed contract parsing."""
1920
parser = VyperParser(str(contracts_dir))
2021
contracts = parser.parse_contracts()
@@ -45,7 +46,7 @@ def test_contract_parsing(contracts_dir):
4546
assert "Get the token balance" in balance_func.docstring
4647

4748

48-
def test_parameter_parsing(contracts_dir):
49+
def test_parameter_parsing(contracts_dir: Path) -> None:
4950
"""Test function parameter parsing."""
5051
parser = VyperParser(str(contracts_dir))
5152
contracts = parser.parse_contracts()
@@ -66,7 +67,7 @@ def test_parameter_parsing(contracts_dir):
6667
assert amount_param.type == "uint256"
6768

6869

69-
def test_empty_contract(tmp_path):
70+
def test_empty_contract(tmp_path: Path) -> None:
7071
"""Test parsing an empty contract."""
7172
contracts_dir = tmp_path / "contracts"
7273
contracts_dir.mkdir()

tests/test_server.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import threading
66
import time
77
import requests
8+
from pathlib import Path
89
from sphinx_autodoc_vyper.server import serve_docs
910

1011

11-
def test_server_start(tmp_path):
12+
def test_server_start(tmp_path: Path) -> None:
1213
"""Test server startup and accessibility."""
1314
# Create mock build directory
1415
build_dir = tmp_path / "docs" / "_build" / "html"
@@ -33,13 +34,13 @@ def test_server_start(tmp_path):
3334
pass
3435

3536

36-
def test_server_missing_docs(tmp_path):
37+
def test_server_missing_docs(tmp_path: Path) -> None:
3738
"""Test server behavior with missing documentation."""
3839
with pytest.raises(FileNotFoundError):
3940
serve_docs()
4041

4142

42-
def _get_free_port():
43+
def _get_free_port() -> int:
4344
"""Get an available port number."""
4445
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
4546
s.bind(("", 0))

0 commit comments

Comments
 (0)