Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-45321: Make Parser metadata type variable importable #60

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/20240718_160401_jsick_DM_45321.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Backwards-incompatible changes

- The `MetadataContainer` type variable has been renamed to `DocumentMetadataT` and is now available from the `lander.ext.parser` module. This allows subclasses to declare the type variable consistently.
3 changes: 2 additions & 1 deletion src/lander/ext/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

__all__ = [
"DocumentMetadata",
"DocumentMetadataT",
"Parser",
"Contributor",
"Person",
Expand All @@ -23,4 +24,4 @@
)
from lander.ext.parser._discovery import ParsingPlugins
from lander.ext.parser._gitdata import GitFile, GitRepository
from lander.ext.parser._parser import Parser
from lander.ext.parser._parser import DocumentMetadataT, Parser
10 changes: 5 additions & 5 deletions src/lander/ext/parser/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from lander.settings import BuildSettings


__all__ = ["Parser", "MetadataContainer"]
__all__ = ["Parser", "DocumentMetadataT"]

#: Type variable of the DocumentMetadata Pydantic object being stored in Parser
MetadataContainer = TypeVar("MetadataContainer", bound=DocumentMetadata)
DocumentMetadataT = TypeVar("DocumentMetadataT", bound=DocumentMetadata)


class Parser(Generic[MetadataContainer], metaclass=ABCMeta):
class Parser(Generic[DocumentMetadataT], metaclass=ABCMeta):
"""Base class for TeX document metadata parsing extensions.

Parameters
Expand Down Expand Up @@ -96,7 +96,7 @@ def git_repository(self) -> GitRepository | None:
return self._git_repository

@property
def metadata(self) -> MetadataContainer:
def metadata(self) -> DocumentMetadataT:
"""Metadata about the document."""
return self._metadata

Expand All @@ -118,7 +118,7 @@ def normalize_source(self, tex_source: str) -> str:
return replace_macros(tex_source, macros)

@abstractmethod
def extract_metadata(self) -> MetadataContainer:
def extract_metadata(self) -> DocumentMetadataT:
"""Extract metadata from the document.

This method should be implemented by parser subclasses.
Expand Down
Loading