Skip to content

Commit 86fbab6

Browse files
authored
All Ruff ANN autofixes (#341)
1 parent 3cd4060 commit 86fbab6

File tree

13 files changed

+88
-86
lines changed

13 files changed

+88
-86
lines changed

paperqa/agents/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def save_settings(
163163
logger.info(f"Settings saved to: {full_settings_path}")
164164

165165

166-
def main():
166+
def main() -> None:
167167
parser = argparse.ArgumentParser(description="PaperQA CLI")
168168

169169
parser.add_argument(

paperqa/agents/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def start(self, name: str) -> None:
166166
except RuntimeError: # No running event loop (not in async)
167167
self.running_timers[name] = TimerData(start_time=time.time())
168168

169-
def stop(self, name: str):
169+
def stop(self, name: str) -> None:
170170
timer_data = self.running_timers.pop(name, None)
171171
if timer_data:
172172
try:

paperqa/agents/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ async def filecheck(self, filename: str, body: str | None = None):
193193

194194
async def add_document(
195195
self, index_doc: dict, document: Any | None = None, max_retries: int = 1000
196-
):
196+
) -> None:
197197
@retry(
198198
stop=stop_after_attempt(max_retries),
199199
wait=wait_random_exponential(multiplier=0.25, max=60),

paperqa/clients/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class DOINotFoundError(Exception):
2-
def __init__(self, message="DOI not found"):
2+
def __init__(self, message="DOI not found") -> None:
33
self.message = message
44
super().__init__(self.message)

paperqa/docs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454

5555

5656
# this is just to reduce None checks/type checks
57-
async def empty_callback(result: LLMResult):
57+
async def empty_callback(result: LLMResult) -> None:
5858
pass
5959

6060

61-
async def print_callback(result: LLMResult):
61+
async def print_callback(result: LLMResult) -> None:
6262
pass
6363

6464

@@ -85,7 +85,7 @@ def handle_default(cls, value: Path | None, info: ValidationInfo) -> Path | None
8585
return PAPERQA_DIR / info.data["name"]
8686
return value
8787

88-
def clear_docs(self):
88+
def clear_docs(self) -> None:
8989
self.texts = []
9090
self.docs = {}
9191
self.docnames = set()
@@ -451,7 +451,7 @@ def delete(
451451
self.deleted_dockeys.add(dockey)
452452
self.texts = list(filter(lambda x: x.doc.dockey != dockey, self.texts))
453453

454-
def _build_texts_index(self):
454+
def _build_texts_index(self) -> None:
455455
texts = [t for t in self.texts if t not in self.texts_index]
456456
self.texts_index.add_texts_and_embeddings(texts)
457457

paperqa/llms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,10 @@ class VectorStore(BaseModel, ABC):
488488
model_config = ConfigDict(extra="forbid")
489489
texts_hashes: set[int] = Field(default_factory=set)
490490

491-
def __contains__(self, item):
491+
def __contains__(self, item) -> bool:
492492
return hash(item) in self.texts_hashes
493493

494-
def __len__(self):
494+
def __len__(self) -> int:
495495
return len(self.texts_hashes)
496496

497497
@abstractmethod
@@ -614,7 +614,7 @@ class LangchainVectorStore(VectorStore):
614614
class_type: type[Embeddable] = Field(default=Embeddable)
615615
model_config = ConfigDict(extra="forbid")
616616

617-
def __init__(self, **data):
617+
def __init__(self, **data) -> None:
618618
raise NotImplementedError(
619619
"Langchain has updated vectorstore internals and this is not yet supported"
620620
)

paperqa/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class LLMResult(BaseModel):
8989
default=0.0, description="Delta time (sec) to last response token's arrival."
9090
)
9191

92-
def __str__(self):
92+
def __str__(self) -> str:
9393
return self.text
9494

9595
@computed_field # type: ignore[prop-decorator]
@@ -198,7 +198,7 @@ def get_citation(self, name: str) -> str:
198198
raise ValueError(f"Could not find docname {name} in contexts.") from exc
199199
return doc.citation
200200

201-
def add_tokens(self, result: LLMResult):
201+
def add_tokens(self, result: LLMResult) -> None:
202202
"""Update the token counts for the given result."""
203203
if result.model not in self.token_counts:
204204
self.token_counts[result.model] = [

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121

2222
@pytest.fixture(autouse=True, scope="session")
23-
def _load_env():
23+
def _load_env() -> None:
2424
load_dotenv()
2525

2626

2727
@pytest.fixture(autouse=True)
28-
def _setup_default_logs():
28+
def _setup_default_logs() -> None:
2929
setup_default_logs()
3030

3131

tests/test_agents.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def test_get_directory_index(agent_test_settings) -> None:
4848
@pytest.mark.asyncio
4949
async def test_get_directory_index_w_manifest(
5050
agent_test_settings, reset_log_levels, caplog # noqa: ARG001
51-
):
51+
) -> None:
5252
agent_test_settings.manifest_file = "stub_manifest.csv"
5353
index = await get_directory_index(settings=agent_test_settings)
5454
assert index.fields == [
@@ -71,7 +71,7 @@ async def test_get_directory_index_w_manifest(
7171
@pytest.mark.flaky(reruns=2, only_rerun=["AssertionError", "httpx.RemoteProtocolError"])
7272
@pytest.mark.parametrize("agent_type", ["fake", "OpenAIFunctionsAgent"])
7373
@pytest.mark.asyncio
74-
async def test_agent_types(agent_test_settings, agent_type):
74+
async def test_agent_types(agent_test_settings, agent_type) -> None:
7575

7676
question = "How can you use XAI for chemical property prediction?"
7777

@@ -87,7 +87,7 @@ async def test_agent_types(agent_test_settings, agent_type):
8787

8888

8989
@pytest.mark.asyncio
90-
async def test_timeout(agent_test_settings):
90+
async def test_timeout(agent_test_settings) -> None:
9191
agent_test_settings.prompts.pre = None
9292
agent_test_settings.agent.timeout = 0.001
9393
agent_test_settings.llm = "gpt-4o-mini"
@@ -287,7 +287,7 @@ def test_functions() -> None:
287287
]
288288

289289

290-
def test_query_request_docs_name_serialized():
290+
def test_query_request_docs_name_serialized() -> None:
291291
"""Test that the query request has a docs_name property."""
292292
request = QueryRequest(query="Are COVID-19 vaccines effective?")
293293
request_data = json.loads(request.model_dump_json())
@@ -298,7 +298,7 @@ def test_query_request_docs_name_serialized():
298298
assert request_data["docs_name"] == "my_doc"
299299

300300

301-
def test_answers_are_striped():
301+
def test_answers_are_striped() -> None:
302302
"""Test that answers are striped."""
303303
answer = Answer(
304304
question="What is the meaning of life?",

tests/test_cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
pytest.skip("agents module is not installed", allow_module_level=True)
1616

1717

18-
def test_can_modify_settings():
18+
def test_can_modify_settings() -> None:
1919
old_argv = sys.argv
2020
old_stdout = sys.stdout
2121
captured_output = io.StringIO()
@@ -37,7 +37,7 @@ def test_can_modify_settings():
3737
os.unlink(pqa_directory("settings") / "unit_test.json")
3838

3939

40-
def test_cli_ask(agent_index_dir: Path, stub_data_dir: Path):
40+
def test_cli_ask(agent_index_dir: Path, stub_data_dir: Path) -> None:
4141
settings = Settings.from_name("debug")
4242
settings.index_directory = agent_index_dir
4343
settings.paper_directory = stub_data_dir
@@ -56,7 +56,9 @@ def test_cli_ask(agent_index_dir: Path, stub_data_dir: Path):
5656
assert found_answer.model_dump_json() == response.model_dump_json()
5757

5858

59-
def test_cli_can_build_and_search_index(agent_index_dir: Path, stub_data_dir: Path):
59+
def test_cli_can_build_and_search_index(
60+
agent_index_dir: Path, stub_data_dir: Path
61+
) -> None:
6062
settings = Settings.from_name("debug")
6163
settings.index_directory = agent_index_dir
6264
index_name = "test"

tests/test_clients.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
],
9797
)
9898
@pytest.mark.asyncio
99-
async def test_title_search(paper_attributes: dict[str, str]):
99+
async def test_title_search(paper_attributes: dict[str, str]) -> None:
100100
async with aiohttp.ClientSession() as session:
101101
client = DocMetadataClient(session, clients=ALL_CLIENTS)
102102
details = await client.query(title=paper_attributes["title"])
@@ -192,7 +192,7 @@ async def test_title_search(paper_attributes: dict[str, str]):
192192
],
193193
)
194194
@pytest.mark.asyncio
195-
async def test_doi_search(paper_attributes: dict[str, str]):
195+
async def test_doi_search(paper_attributes: dict[str, str]) -> None:
196196
async with aiohttp.ClientSession() as session:
197197
client = DocMetadataClient(session, clients=ALL_CLIENTS)
198198
details = await client.query(doi=paper_attributes["doi"])
@@ -210,7 +210,7 @@ async def test_doi_search(paper_attributes: dict[str, str]):
210210

211211
@pytest.mark.vcr
212212
@pytest.mark.asyncio
213-
async def test_bulk_doi_search():
213+
async def test_bulk_doi_search() -> None:
214214
dois = [
215215
"10.1063/1.4938384",
216216
"10.48550/arxiv.2312.07559",
@@ -228,7 +228,7 @@ async def test_bulk_doi_search():
228228

229229
@pytest.mark.vcr
230230
@pytest.mark.asyncio
231-
async def test_bulk_title_search():
231+
async def test_bulk_title_search() -> None:
232232
titles = [
233233
(
234234
"Effect of native oxide layers on copper thin-film tensile properties: A"
@@ -253,7 +253,7 @@ async def test_bulk_title_search():
253253

254254
@pytest.mark.vcr
255255
@pytest.mark.asyncio
256-
async def test_bad_titles():
256+
async def test_bad_titles() -> None:
257257
async with aiohttp.ClientSession() as session:
258258
client = DocMetadataClient(session)
259259
details = await client.query(title="askldjrq3rjaw938h")
@@ -269,7 +269,7 @@ async def test_bad_titles():
269269

270270
@pytest.mark.vcr
271271
@pytest.mark.asyncio
272-
async def test_bad_dois():
272+
async def test_bad_dois() -> None:
273273
async with aiohttp.ClientSession() as session:
274274
client = DocMetadataClient(session)
275275
details = await client.query(title="abs12032jsdafn")
@@ -278,7 +278,7 @@ async def test_bad_dois():
278278

279279
@pytest.mark.vcr
280280
@pytest.mark.asyncio
281-
async def test_minimal_fields_filtering():
281+
async def test_minimal_fields_filtering() -> None:
282282
async with aiohttp.ClientSession() as session:
283283
client = DocMetadataClient(session)
284284
details = await client.query(
@@ -303,7 +303,7 @@ async def test_minimal_fields_filtering():
303303

304304
@pytest.mark.vcr
305305
@pytest.mark.asyncio
306-
async def test_s2_only_fields_filtering():
306+
async def test_s2_only_fields_filtering() -> None:
307307
async with aiohttp.ClientSession() as session:
308308
# now get with authors just from one source
309309
s2_client = DocMetadataClient(session, clients=[SemanticScholarProvider])
@@ -373,7 +373,7 @@ async def test_crossref_journalquality_fields_filtering() -> None:
373373

374374
@pytest.mark.vcr
375375
@pytest.mark.asyncio
376-
async def test_author_matching():
376+
async def test_author_matching() -> None:
377377
async with aiohttp.ClientSession() as session:
378378
crossref_client = DocMetadataClient(session, clients=[CrossrefProvider])
379379
s2_client = DocMetadataClient(session, clients=[SemanticScholarProvider])
@@ -402,7 +402,7 @@ async def test_author_matching():
402402

403403
@pytest.mark.vcr
404404
@pytest.mark.asyncio
405-
async def test_odd_client_requests():
405+
async def test_odd_client_requests() -> None:
406406
# try querying using an authors match, but not requesting authors back
407407
async with aiohttp.ClientSession() as session:
408408
client = DocMetadataClient(session)
@@ -449,7 +449,7 @@ async def test_odd_client_requests():
449449

450450

451451
@pytest.mark.asyncio
452-
async def test_ensure_robust_to_timeouts(monkeypatch):
452+
async def test_ensure_robust_to_timeouts(monkeypatch) -> None:
453453
# 0.15 should be short enough to not get a response in time.
454454
monkeypatch.setattr(paperqa.clients.crossref, "CROSSREF_API_REQUEST_TIMEOUT", 0.05)
455455
monkeypatch.setattr(
@@ -466,7 +466,7 @@ async def test_ensure_robust_to_timeouts(monkeypatch):
466466

467467

468468
@pytest.mark.asyncio
469-
async def test_bad_init():
469+
async def test_bad_init() -> None:
470470
with pytest.raises(
471471
ValueError, match="At least one MetadataProvider must be provided."
472472
):
@@ -475,7 +475,7 @@ async def test_bad_init():
475475

476476
@pytest.mark.vcr
477477
@pytest.mark.asyncio
478-
async def test_ensure_sequential_run(caplog, reset_log_levels): # noqa: ARG001
478+
async def test_ensure_sequential_run(caplog, reset_log_levels) -> None: # noqa: ARG001
479479
caplog.set_level(logging.DEBUG)
480480
# were using a DOI that is NOT in crossref, but running the crossref client first
481481
# we will ensure that both are run sequentially
@@ -512,7 +512,7 @@ async def test_ensure_sequential_run(caplog, reset_log_levels): # noqa: ARG001
512512
@pytest.mark.asyncio
513513
async def test_ensure_sequential_run_early_stop(
514514
caplog, reset_log_levels # noqa: ARG001
515-
):
515+
) -> None:
516516
caplog.set_level(logging.DEBUG)
517517
# now we should stop after hitting s2
518518
async with aiohttp.ClientSession() as session:

tests/test_configs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
)
1212

1313

14-
def test_prompt_settings_validation():
14+
def test_prompt_settings_validation() -> None:
1515
with pytest.raises(ValidationError):
1616
PromptSettings(summary="Invalid {variable}")
1717

@@ -27,13 +27,13 @@ def test_prompt_settings_validation():
2727
assert valid_pre_settings.pre == "{question}"
2828

2929

30-
def test_get_formatted_variables():
30+
def test_get_formatted_variables() -> None:
3131
template = "This is a test {variable} with {another_variable}"
3232
variables = get_formatted_variables(template)
3333
assert variables == {"variable", "another_variable"}
3434

3535

36-
def test_get_settings_with_valid_config():
36+
def test_get_settings_with_valid_config() -> None:
3737
settings = get_settings("fast")
3838
assert not settings.parsing.use_doc_details
3939

@@ -46,7 +46,7 @@ def test_get_settings_missing_file() -> None:
4646
get_settings("missing_config")
4747

4848

49-
def test_settings_default_instantiation():
49+
def test_settings_default_instantiation() -> None:
5050
settings = Settings()
5151
assert "gpt-" in settings.llm
5252
assert settings.answer.evidence_k == 10

0 commit comments

Comments
 (0)