Split links away from tmt.base.core#4901
Open
happz wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors link-related logic by moving Link, Links, and LinkNeedle classes from tmt.base.core to a new tmt.base.links module. Feedback identifies several missing runtime imports for Links and FmfId that will cause NameError exceptions in tmt/base/core.py and tmt/base/links.py. Additionally, update type hints in tmt/utils/jira.py to import directly from the new module instead of using re-exports.
|
|
||
| def _normalize_link(key_address: str, value: _RawLinks, logger: tmt.log.Logger) -> 'Links': | ||
| def _normalize_link(key_address: str, value: '_RawLinks', logger: tmt.log.Logger) -> 'Links': | ||
| return Links(data=value) |
Contributor
|
|
||
| # Append link with appropriate relation | ||
| links = Links(data=list(cast(list[_RawLink], Story._opt('link', [])))) | ||
| links = Links(data=list(cast(list['_RawLink'], Story._opt('link', [])))) |
Contributor
Comment on lines
+216
to
+238
| def to_spec(self) -> _RawLinkRelation: | ||
| """ | ||
| Convert to a form suitable for saving in a specification file | ||
|
|
||
| No matter what the original specification was, every link will | ||
| generate the very same type of specification, the ``relation: target`` | ||
| one. | ||
|
|
||
| Output of this method is fully compatible with specification, and when | ||
| given to :py:meth:`from_spec`, it shall create a ``Link`` instance | ||
| with the same properties as the original one. | ||
|
|
||
| [1] https://tmt.readthedocs.io/en/stable/spec/core.html#link | ||
| """ | ||
|
|
||
| spec: _RawLinkRelation = { | ||
| self.relation: self.target.to_spec() if isinstance(self.target, FmfId) else self.target | ||
| } | ||
|
|
||
| if self.note is not None: | ||
| spec['note'] = self.note | ||
|
|
||
| return spec |
Contributor
There was a problem hiding this comment.
Import FmfId locally within this method. It is used in the isinstance check but is currently only imported inside from_spec, leading to a NameError at runtime.
def to_spec(self) -> _RawLinkRelation:
"""
Convert to a form suitable for saving in a specification file
No matter what the original specification was, every link will
generate the very same type of specification, the relation: target
one.
Output of this method is fully compatible with specification, and when
given to :py:meth:from_spec, it shall create a Link instance
with the same properties as the original one.
[1] https://tmt.readthedocs.io/en/stable/spec/core.html#link
"""
from tmt.base.core import FmfId
spec: _RawLinkRelation = {
self.relation: self.target.to_spec() if isinstance(self.target, FmfId) else self.target
}
if self.note is not None:
spec['note'] = self.note
return spec| if TYPE_CHECKING: | ||
| import jira | ||
|
|
||
| import tmt.base.links |
Contributor
There was a problem hiding this comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist