-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Use attrs with all Repr classes #6739
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
Conversation
reprfuncargs = attr.ib(type=Optional["ReprFuncArgs"]) | ||
reprlocals = attr.ib(type=Optional["ReprLocals"]) | ||
# XXX/NOTE: changed arg name: filelocrepr => reprfileloc | ||
reprfileloc = attr.ib(type=Optional["ReprFileLocation"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we can go with s/filelocrepr/reprfileloc
, or should it support the old name? (it was at least used internally).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we can go with
s/filelocrepr/reprfileloc
, or should it support the old name? (it was at least used internally).
Still an open question..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is OK to change the parameter name and keep the attribute reprfileloc
: I doubt people create ReprEntry
explicitly (it is not possible to import ReprEntry
through the public API).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except the mixin class (I really dislike those!), which makes me wonder if there is particular reason you decided to break the ExceptionRepr
subclassing? The following change on top of yours brings it back and seems to work fine:
diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py
index 8c349c17e..2bf3b76fa 100644
--- a/src/_pytest/_code/code.py
+++ b/src/_pytest/_code/code.py
@@ -928,12 +928,8 @@ class TerminalRepr:
raise NotImplementedError()
-class _SectionsRepr:
- """Mixin for handling sections.
-
- Only `ExceptionRepr` takes it in `__init__`, but others use it also.
- """
-
+@attr.s
+class ExceptionRepr(TerminalRepr):
def __attrs_post_init__(self):
self.sections = [] # type: List[Tuple[str, str, str]]
@@ -947,12 +943,7 @@ class _SectionsRepr:
@attr.s
-class ExceptionRepr(_SectionsRepr, TerminalRepr):
- sections = attr.ib(type=List[Tuple[str, str, str]])
-
-
-@attr.s
-class ExceptionChainRepr(_SectionsRepr, TerminalRepr):
+class ExceptionChainRepr(ExceptionRepr):
chain = attr.ib(
type=Sequence[
Tuple["ReprTraceback", Optional["ReprFileLocation"], Optional[str]]
@@ -976,7 +967,7 @@ class ExceptionChainRepr(_SectionsRepr, TerminalRepr):
@attr.s
-class ReprExceptionInfo(_SectionsRepr, TerminalRepr):
+class ReprExceptionInfo(ExceptionRepr):
reprtraceback = attr.ib(type="ReprTraceback")
reprcrash = attr.ib(type="ReprFileLocation")
@bluetech |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!
reprfuncargs = attr.ib(type=Optional["ReprFuncArgs"]) | ||
reprlocals = attr.ib(type=Optional["ReprLocals"]) | ||
# XXX/NOTE: changed arg name: filelocrepr => reprfileloc | ||
reprfileloc = attr.ib(type=Optional["ReprFileLocation"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is OK to change the parameter name and keep the attribute reprfileloc
: I doubt people create ReprEntry
explicitly (it is not possible to import ReprEntry
through the public API).
This is done because ReprEntry's `filelocrepr` argument was renamed to `reprfileloc`. For details, see: pytest-dev/pytest#6739
Co-authored-by: Ran Benita <[email protected]> (cherry picked from commit b11bfa1) Ref: pytest-dev#6739 Conflicts: src/_pytest/_code/code.py
Follow-up to #6732.