Skip to content
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

false negative with dangerous-default-value #8826

Closed
dpinol opened this issue Jul 6, 2023 · 3 comments
Closed

false negative with dangerous-default-value #8826

dpinol opened this issue Jul 6, 2023 · 3 comments
Labels
dataclasses Duplicate 🐫 Duplicate of an already existing issue False Negative 🦋 No message is emitted but something is wrong with the code

Comments

@dpinol
Copy link

dpinol commented Jul 6, 2023

Bug description

# pylint: disable=missing-module-docstring
from dataclasses import dataclass
# pylint: disable=missing-class-docstring
# pylint: disable=too-few-public-methods
class Arg:
    def __init__(self):
        self.field = 4


@dataclass(frozen=True)
class Frozen:
    field: int = 3


# pylint: disable=missing-function-docstring
def func(arg=Arg()):
    arg.field = 5


# pylint: disable=missing-function-docstring
def func2(frozen=Frozen()):
    print(frozen.field)

Configuration

No response

Command used

pylint kk.py

Pylint output

-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 8.00/10, +2.00)

Expected behavior

ttbomk it should report dangerous-default-value for func, but not for func2 since the argument is readonly.

Pylint version

pylint 2.17.4
astroid 2.15.5
Python 3.11.3 (main, May  2 2023, 16:42:49) [GCC 11.3.0]

OS / Environment

ubuntu 22.10

Additional dependencies

No response

@dpinol dpinol added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jul 6, 2023
@DanielNoord DanielNoord added False Negative 🦋 No message is emitted but something is wrong with the code dataclasses Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 6, 2023
@jacobtylerwalls
Copy link
Member

Thanks for the report! IMO this is a duplicate of #4659. Please feel free to review the PR for it and offer a view on moving it forward.

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2023
@jacobtylerwalls jacobtylerwalls added Duplicate 🐫 Duplicate of an already existing issue and removed Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Jul 6, 2023
@dpinol
Copy link
Author

dpinol commented Jul 6, 2023

Hi, thanks for the quick answer.
IMO #4659 is different because it refers to immutable stateful objects.
What I mean is that dangerous-default-value refers to "a mutable value as list or dictionary". If "dangerous-default-value" is only meant for dicts and lists, I think the documentation should be more explicit to say instead "list or dictionary"

@jacobtylerwalls
Copy link
Member

IMO #4659 is different because it refers to immutable stateful objects.

As I read #4659 it was suggesting collapsing the distinction between "mutable" and "stateful", not introducing a distinctive "immutable stateful" class.

In other words, suggesting expanding the message beyond dicts and lists to callables that we can reasonably detect return something other than a constant. Here, you have a callable Arg returning a dataclass instance, which isn't a constant. A frozen dataclass would be like a constant, so I left a comment to that effect.

If "dangerous-default-value" is only meant for dicts and lists, I think the documentation should be more explicit to say instead "list or dictionary"

Did you mean if "is not only meant"? Yes, the docs would need to be updated as part of that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dataclasses Duplicate 🐫 Duplicate of an already existing issue False Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
Development

No branches or pull requests

3 participants