-
Notifications
You must be signed in to change notification settings - Fork 28
Fix remove_class when methods have decorators #76
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
Open
Code0x58
wants to merge
1
commit into
pytest-dev:main
Choose a base branch
from
Code0x58:fix-49
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class TestAssertNotEqual(TestCase): | ||
|
||
def test_you(self): | ||
pass | ||
|
||
|
||
@property | ||
def test_me(self): | ||
[ | ||
item | ||
for item in sequence | ||
if item | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
def test_you(self): | ||
pass | ||
|
||
|
||
@property | ||
def test_me(self): | ||
[ | ||
item | ||
for item in sequence | ||
if item | ||
] |
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
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.
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.
This seems weird to me, wouldn't be better to keep the entire class if we find a decorator?
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 haven't looks at this in a while (I suppose the nature of a one-shot tool), so my recollection might be a bit off, but:
It does seem weird, particularly with the choice of the property decorator as an example, as what simple transformation would you do for
property
, let alone generic things?Some decorators work transparently with/without classes (e.g.
functools.cache
), so sometimes leaving the decorator is fine/good. Then there's all the other cases, which are probably best left to be sorted by hand - at least leaving the decorator shows you what was there so you can work from there, instead of using agit diff
etc. So keeping the decorators seems better to me than dropping it, as I think currently happens (have yet to confirm, but I imagine that was what inspired me to make this change when I used the tool ages ago).Flat out avoiding transforming a class when a potentially non-trivial/breaking change is detected does sound like a decent option, although I'm not sure it is what happens in the tool at present. In the use case I recall, I didn't mind having to put in a fix for the odd small non-trivial/breaking bit after the tool handled a large amount of trivial cases, so I would like the option to keep the "I'll do most of the work, you just fix the odd like leftover" tool behaviour.
Going through that makes me think think that this is at least an improvement, with potential for further improvement down the line as well
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.
property is the prime example of removing the class Is plain wrong
Any descriptor is simply plain broken without a class
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.
Yeah I agree, if we have a decorator, we should not attempt to remove the class itself... we can leave the class there, and still convert
self.assert*
methods toassert
,assertRaises
topytest.raises
, etc, but leave the class intact.