Skip to content

Commit 03f8728

Browse files
authored
fix warnings (#43)
* Fix warnings with dict.fromkeys * Add tox * Make CI a little more strict
1 parent 3bbdda8 commit 03f8728

File tree

11 files changed

+37
-11
lines changed

11 files changed

+37
-11
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ jobs:
3636
run: |
3737
uv sync
3838
uv run pre-commit run --all
39-
uv run pytest
39+
uv run pytest ./tests
40+
uv run mypy ./src
41+
uv run ruff check
42+
uv run ruff format --check

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,16 @@ build-backend = "hatchling.build"
113113

114114
[tool.hatch.version]
115115
path = "src/bibx/__init__.py"
116+
117+
[tool.tox]
118+
requires = ["tox>=4.24.2"]
119+
env_list = ["3.9", "3.10", "3.11", "3.12", "3.13"]
120+
121+
[tool.tox.env_run_base]
122+
deps = [
123+
"pytest>=8.3.5",
124+
"ruff>=0.9.10",
125+
"mypy~=1.9.0",
126+
"types-requests>=2.32.0.20241016",
127+
]
128+
commands = [["ruff", "check"], ["pytest", "tests/"], ["mypy", "src/"]]

src/bibx/builders/openalex.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ def _extract_doi(url: str) -> str:
9494

9595
@classmethod
9696
def _work_to_article(cls, work: Work) -> Article:
97+
journal = None
98+
if work.primary_location and work.primary_location.source:
99+
journal = work.primary_location.source.display_name
100+
permalink = None
101+
if work.primary_location and work.primary_location.landing_page_url:
102+
permalink = work.primary_location.landing_page_url
97103
article = Article(
98104
label=work.id,
99105
ids={
@@ -105,16 +111,12 @@ def _work_to_article(cls, work: Work) -> Article:
105111
authors=[cls._invert_name(a.author.display_name) for a in work.authorships],
106112
year=work.publication_year,
107113
title=work.title,
108-
journal=(
109-
work.primary_location
110-
and work.primary_location.source
111-
and work.primary_location.source.display_name
112-
),
114+
journal=journal,
113115
volume=work.biblio.volume,
114116
issue=work.biblio.issue,
115117
page=work.biblio.first_page,
116118
doi=cls._extract_doi(work.doi) if work.doi else None,
117-
_permalink=work.primary_location and work.primary_location.landing_page_url,
119+
_permalink=permalink,
118120
times_cited=work.cited_by_count,
119121
references=[cls._reference_to_article(r) for r in work.referenced_works],
120122
keywords=[k.display_name for k in work.keywords],

src/bibx/builders/scopus_csv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ def build(self) -> Collection:
9191
articles = self._articles_from_files()
9292
return Collection(articles=Collection.deduplicate_articles(list(articles)))
9393

94-
def _articles_from_files(self) -> Generator[Article]:
94+
def _articles_from_files(self) -> Generator[Article, None, None]:
9595
for file in self._files:
9696
yield from self._parse_file(file)
9797

98-
def _parse_file(self, file: TextIO) -> Generator[Article]:
98+
def _parse_file(self, file: TextIO) -> Generator[Article, None, None]:
9999
reader = csv.DictReader(file)
100100
for row in reader:
101101
datum = Row.model_validate(row)

src/bibx/builders/wos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def _parse(cls, key: str, value: list[str]) -> dict:
369369
if key in cls.FIELDS:
370370
field = cls.FIELDS[key]
371371
parsed_value = field.parse(value)
372-
return {new_key: parsed_value for new_key in [field.key, *field.aliases]}
372+
return dict.fromkeys([field.key, *field.aliases], parsed_value)
373373

374374
logger.debug("Found an unknown field with key %s and value %s", key, value)
375375
return {key: _ident(value)}

src/bibx/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _uniqe_articles_by_id(cls, articles: list[Article]) -> dict[str, Article]:
7474
articles.append(article)
7575
visited.add(id(article))
7676
merged = reduce(Article.merge, articles)
77-
article_by_id.update({id_: merged for id_ in ids})
77+
article_by_id.update(dict.fromkeys(ids, merged))
7878

7979
return article_by_id
8080

stubs/bibtexparser/bparser.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class BibDatabase:
2+
entries: list[dict]

stubs/networkx/algorithms/__init__.pyi

Whitespace-only changes.

stubs/networkx/algorithms/community/__init__.pyi

Whitespace-only changes.

stubs/networkx/classes/__init__.pyi

Whitespace-only changes.

0 commit comments

Comments
 (0)