Skip to content

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

Open
@ruancomelli

Description

@ruancomelli

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions