-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
B006 (unsafe fix) : does not fix correctly with @overload #10083
Comments
Thanks for reporting this improvement. I summarised the issue again in my own words after I have played with the example for a bit. The if <argument> is None:
<argument> = [] as the first statement in the body which in itself is the semantically correct refactor. However, inserting the statement is undesired if the function has a stub body. I don't think we necessarily have to test if the function has the |
Yes that's correct, it also replaces the typing by
Well see ! I think it is the best way to handle it ! (to be clear : no statement added in stubs but method signature modified) Except at the end there's not a stub body.class Test:
@overload
@classmethod
def query(
cls,
my_list: list[Whatever | int] = [],
) -> Whatever:
...
@overload
@classmethod
def query(
cls,
my_list: list[Whatever | int] = [],
) -> Whatever:
...
@classmethod
def query(cls, my_list: list[Whatever | int] = []) -> Whatever:
raise NotImplementedError("") |
I added code that identifies all functions, where the body consists only out of a docstring, the ... literal and/or the pass keyword as a stub and doesn't modify the body then. But now that I think more about it, I also find the case where the function body only raises a NotImplementedError compelling. Should that maybe also be identified as a stub? |
@Philipp-Thiel - Sure, that seems like a reasonable extension. You can use the |
…`) (astral-sh#10152) ## Summary Adapts the fix for rule B006 to no longer modify the body of function stubs, while retaining the change in method signature. ## Test Plan The existing tests for B006 were adapted to reflect this change in behavior. ## Relevant issue astral-sh#10083
…unctions (#10990) ## Summary As discussed in #10083 (comment), stubs detection now also covers the case where the function body raises NotImplementedError and does nothing else. ## Test Plan Tests for the relevant cases were added in B006_8.py
It should not touch overloaded functions except to change the right argument :
But must not add logic in it :
So the result should look like this for overloaded methods :
NB : this overloaded method has no sens, I removed the unnecessary.
The text was updated successfully, but these errors were encountered: