Skip to content

Commit

Permalink
Merge pull request #60 from lsst-sqre:tickets/DM-45321
Browse files Browse the repository at this point in the history
DM-45321: Make Parser metadata type variable importable
  • Loading branch information
jonathansick authored Jul 18, 2024
2 parents 41ff2cc + c6a4c7f commit 8f6d868
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
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

0 comments on commit 8f6d868

Please sign in to comment.