-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
unused-argument for required argument in __new__ #3670
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Can you provide an example? |
class Example:
""" Class doc string """
__instances = dict()
def __init__(self, name, x, y, z, test=None):
self.name = name
self.x = x
self.y = y
self.z = z
if test is not None:
self.test = test
else:
self. test = 'some default'
def __new__(self, name, x, y, z, test=None):
if name in self.__instances:
assert self.__instances[name].x == x
return self.__instances[name]
else:
instance = super(Example, cls).__new__(cls)
cls.__instances[name] = instance
return instance |
I just wrote the example in the editor to remove application specific details, but the above should illustrate what I meant. |
Or to make it simpler: class Example:
def __new__(cls, *args, **kwargs):
# no need to pass args, kwargs here,
# but pylint raises unused-argument
return object.__new__(cls)
def __init__(self, *args, **kwargs):
# args and kwargs were passed implicitly from __new__
# do object initialization. |
Yes, thank you @pwwang, I'll admit that is a better (and simpler) example, thank you :) |
Hi! I'm running into this issue now, and I'm just wondering if this is solved? Or do you have to disable the warning for all __new__ functions? (Not that you need to redefine __new__ too often) |
One of the check for unused arguments looks for unused arguments in `__new`. Problem, `__new__` have to match the arguments of `__init__` even if it does not use them. This behavior was introduced in the following commit: pylint-dev@ebb64fc. There is no details on why `__new__` has been added to the list. As it's done for special methods with fixed number of parameters, there should not be unused arguments check for `__new__`, I removed it from the tested values. Fixes pylint-dev#3670
One of the check for `unused-argument` looks for unused arguments in `__new__`. Problem, `__new__` have to match the arguments of `__init__` even if it does not use them. This behavior was introduced in the following commit: pylint-dev@ebb64fc. There is no details on why `__new__` has been added to the list. As it's done for special methods with fixed number of parameters, there should not be unused arguments check for `__new__`, I removed it from the checked methods. Fixes pylint-dev#3670
One of the check for `unused-argument` looks for unused arguments in `__new__`. Problem, `__new__` have to match the arguments of `__init__` even if it does not use them. This behavior was introduced in the following commit: pylint-dev@ebb64fc. There is no details on why `__new__` has been added to the list. As it's done for special methods with fixed number of parameters, there should not be unused arguments check for `__new__`, I removed it from the checked methods. Fixes pylint-dev#3670
Problem: the special method `__new__` must match the arguments of the `__init__` method even if `__new__` method does not use them. This generate `unused-argument` for the `__new__` method. Fix: the unused arguments check should not be done on the `__new__` method if the `__init__` method is defined in the same class. Fixes pylint-dev#3670
Problem: the special method `__new__` must match the arguments of the `__init__` method even if `__new__` method does not use them. This generate `unused-argument` for the `__new__` method. Fix: the unused arguments check should not be done on the `__new__` method if the `__init__` method is defined in the same class. Fixes pylint-dev#3670
Problem: the special method `__new__` must match the arguments of the `__init__` method even if `__new__` method does not use them. This generate `unused-argument` for the `__new__` method. Fix: the unused arguments check should not be done on the `__new__` method if the `__init__` method is defined in the same class. Fixes pylint-dev#3670
Problem: the special method `__new__` must match the arguments of the `__init__` method even if `__new__` method does not use them. This generate `unused-argument` for the `__new__` method. Fix: the unused arguments check should not be done on the `__new__` method if the `__init__` method is defined in the same class. Fixes pylint-dev#3670
Problem: the special method `__new__` must match the arguments of the `__init__` method even if `__new__` method does not use them. This generate `unused-argument` for the `__new__` method. Fix: the unused arguments check should not be done on the `__new__` method if the `__init__` method is defined in the same class. Update `unused-argument` test to include a check for the case of `__init__` and `__new__` being defined in a class but `__new__` does not use all of the argument. This is fine because `__new__` must have the same argument of `__init__`. Update with a second check in case of `__init__` being not defined in a class. Then the unused arguments check must be done on `__new__`. Fixes #3670
Problem: the special method `__new__` must match the arguments of the `__init__` method even if `__new__` method does not use them. This generate `unused-argument` for the `__new__` method. Fix: the unused arguments check should not be done on the `__new__` method if the `__init__` method is defined in the same class. Update `unused-argument` test to include a check for the case of `__init__` and `__new__` being defined in a class but `__new__` does not use all of the argument. This is fine because `__new__` must have the same argument of `__init__`. Update with a second check in case of `__init__` being not defined in a class. Then the unused arguments check must be done on `__new__`. Fixes #3670 (cherry picked from commit 156da64)
Problem: the special method `__new__` must match the arguments of the `__init__` method even if `__new__` method does not use them. This generate `unused-argument` for the `__new__` method. Fix: the unused arguments check should not be done on the `__new__` method if the `__init__` method is defined in the same class. Update `unused-argument` test to include a check for the case of `__init__` and `__new__` being defined in a class but `__new__` does not use all of the argument. This is fine because `__new__` must have the same argument of `__init__`. Update with a second check in case of `__init__` being not defined in a class. Then the unused arguments check must be done on `__new__`. Fixes #3670 (cherry picked from commit 156da64) Co-authored-by: Théo Battrel <theo.util@protonmail.ch>
Uh oh!
There was an error while loading. Please reload this page.
I have a class where I overload the new() call.
The new
__new__()
call is required to have the same arguments as the__init__()
, so after I make some checks, I callsuper().__new__(cls)
. In this, the input arguments are implicitly passed on to__init__()
.However, I get the unused-argument pylint warning, as I do not use all the arguments within the
__new__()
.The text was updated successfully, but these errors were encountered: