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

Fix Incorrect Use of update Method in remove_prefix_from_names Function #1229

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

voronor
Copy link

@voronor voronor commented Nov 23, 2024

Issue

In the function remove_prefix_from_names, there is a potential issue with how the update method is used:

contract.update([("name", remove_prefix(contract['name'], 'openzeppelin_presets_'))])

The update method expects a dictionary, but the current implementation passes a list of tuples. This can lead to a runtime error.


Proposed Fix

Replace the list of tuples with a dictionary to align with the correct usage of update:

contract.update({"name": remove_prefix(contract['name'], 'openzeppelin_presets_')})

Why This Fix Is Important

  1. Prevents Runtime Errors: The current implementation is incompatible with the update method's API, which could cause the program to fail at runtime.
  2. Ensures Proper API Usage: The update method is designed for updating a dictionary with another dictionary or key-value pairs. Using it as intended ensures clarity and maintainability.

Updated Code

The corrected function is:

def remove_prefix_from_names(contracts):
    for contract in contracts:
        contract.update({"name": remove_prefix(contract['name'], 'openzeppelin_presets_')})
    return contracts

This fix ensures that the code functions as intended without errors, while maintaining compatibility with Python's dictionary API.


Testing

  • Verified that the updated remove_prefix_from_names function correctly removes the prefix without raising any exceptions.
  • Confirmed that the rest of the pipeline processes the updated contracts as expected.

Impact

This fix ensures the stability and correctness of the codebase, particularly for processing contract names in the remove_prefix_from_names function.

  • Tests
  • Documentation
  • Added entry to CHANGELOG.md
  • Tried the feature on a public network

Copy link

codecov bot commented Nov 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.26%. Comparing base (3fdef27) to head (8ace80f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1229   +/-   ##
=======================================
  Coverage   92.26%   92.26%           
=======================================
  Files          59       59           
  Lines        1811     1811           
=======================================
  Hits         1671     1671           
  Misses        140      140           

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3fdef27...8ace80f. Read the comment docs.

---- 🚨 Try these New Features:

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

Successfully merging this pull request may close these issues.

1 participant