diff --git a/src/citeable/_entries.py b/src/citeable/_entries.py index e44f08e..a15d289 100644 --- a/src/citeable/_entries.py +++ b/src/citeable/_entries.py @@ -155,7 +155,7 @@ class Article(CitationBase): """An ``@article`` BibTeX entry.""" journal: str - volume: int + volume: int | None pages: str | None article_number: str | None number: int | None @@ -166,8 +166,8 @@ def __init__( title: str, year: int, journal: str, - volume: int, *, + volume: int | None = None, pages: str | None = None, article_number: str | None = None, number: int | None = None, @@ -178,10 +178,6 @@ def __init__( app: str | None = None, ) -> None: require_field(journal, "journal", "Article") - require_field(volume, "volume", "Article") - if pages is None and article_number is None: - msg = "Article requires 'pages' or 'article_number'; both are None" - raise ValueError(msg) self._init_base( author, title, year, doi=doi, url=url, note=note, key=key, app=app @@ -199,8 +195,9 @@ def __str__(self) -> str: _format_bibtex_field("title", self.title), _format_bibtex_field("journal", self.journal), _format_bibtex_field("year", str(self.year)), - _format_bibtex_field("volume", str(self.volume)), ] + if self.volume is not None: + lines.append(_format_bibtex_field("volume", str(self.volume))) if self.number is not None: lines.append(_format_bibtex_field("number", str(self.number))) if self.pages is not None: @@ -217,8 +214,9 @@ def _repr_fields(self) -> list[tuple[str, object]]: ("title", self.title), ("year", self.year), ("journal", self.journal), - ("volume", self.volume), ] + if self.volume is not None: + fields.append(("volume", self.volume)) if self.pages is not None: fields.append(("pages", self.pages)) if self.article_number is not None: diff --git a/tests/test_entries.py b/tests/test_entries.py index d4a8dea..b01ebf4 100644 --- a/tests/test_entries.py +++ b/tests/test_entries.py @@ -44,27 +44,17 @@ def test_article_with_article_number(): assert a.pages is None -def test_article_missing_pages_and_article_number(): - with pytest.raises(ValueError, match=r"pages.*article_number"): - Article( - author=["Smith, Jane"], - title="Something", - year=2024, - journal="Nature", - volume=1, - ) - - -def test_article_missing_volume(): - with pytest.raises(ValueError, match="Article requires 'volume'"): - Article( - author=["Smith, Jane"], - title="Something", - year=2024, - journal="Nature", - volume=None, # type: ignore[arg-type] - pages="1-10", - ) +def test_article_advance_access(): + a = Article( + author=["Smith, Jane"], + title="Something", + year=2024, + journal="Nature", + doi="10.1234/example", + ) + assert a.volume is None + assert a.pages is None + assert a.article_number is None def test_article_missing_journal():