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

Refactoring merge-dict-assign does not trigger when the value being set is a function parameter #342

Open
2 tasks done
ruancomelli opened this issue Apr 27, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@ruancomelli
Copy link
Contributor

Checklist

  • I have searched the Sourcery documentation for the issue, and found nothing
  • I have checked there are no open bugs referencing the same bug or problem

Description

Related to #339 (comment).

Code snippet that reproduces issue

1 - Case reported in #339

Input:

def __init__(self, toUserName, fromUserName, mediaId):
    self.__dict = {}
    self.__dict['ToUserName'] = toUserName
    self.__dict['FromUserName'] = fromUserName
    self.__dict["CreateTime"] = int(time.time())
    self.__dict["MediaId"] = mediaId

Expected refactored code:

def __init__(self, toUserName, fromUserName, mediaId):
    self.__dict = {
        'ToUserName': toUserName,
        'FromUserName': fromUserName,
        "CreateTime": int(time.time()),
        "MediaId": mediaId
    }

Actual refactored code:

def __init__(self, toUserName, fromUserName, mediaId):
    self.__dict = {
        'ToUserName': toUserName,
        'FromUserName': fromUserName,
        "CreateTime": int(time.time()),
    }
    self.__dict["MediaId"] = mediaId

2 - Simplified version

The bug can more easily be reproduced with the following snippets:
Input:

def foo(mediaId):
    d = {}
    d["CreateTime"] = int(time.time())
    d["MediaId"] = mediaId

Expected refactored code:

def foo(mediaId):
    d = {"CreateTime": int(time.time()), "MediaId": mediaId}

Actual refactored code:

def foo(mediaId):
    d = {"CreateTime": int(time.time())}
    d["MediaId"] = mediaId

Debug Information

Sourcery Version: 1.2.0

@ruancomelli ruancomelli added the bug Something isn't working label Apr 27, 2023
@ruancomelli ruancomelli added enhancement New feature or request and removed bug Something isn't working labels Apr 27, 2023
@ruancomelli
Copy link
Contributor Author

Relabeled this as an enhancement proposal since the refactoring is still correct.
We definitely want Sourcery to keep on refactoring until all items are added to the dictionary instantiation, but this is not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant