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

feat: add unused import pass #3

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

feat: add unused import pass #3

wants to merge 1 commit into from

Conversation

tserg
Copy link
Owner

@tserg tserg commented Feb 11, 2023

No description provided.

Comment on lines +3 to +6
# @dev Implementation of ERC-20 token standard.
# @author Takayuki Jimba (@yudetamago)
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep only relevant code in those examples, as you did everywhere else. Starting by all those comments, and I'll suggest other removals.

Suggested change
# @dev Implementation of ERC-20 token standard.
# @author Takayuki Jimba (@yudetamago)
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from vyper's examples so I prefer leaving it as it is.

Comment on lines +100 to +149


@external
def mint(_to: address, _value: uint256):
"""
@dev Mint an amount of the token and assigns it to an account.
This encapsulates the modification of balances such that the
proper events are emitted.
@param _to The account that will receive the created tokens.
@param _value The amount that will be created.
"""
assert msg.sender == self.minter
assert _to != empty(address)
self.totalSupply += _value
self.balanceOf[_to] += _value
log Transfer(empty(address), _to, _value)


@internal
def _burn(_to: address, _value: uint256):
"""
@dev Internal function that burns an amount of the token of a given
account.
@param _to The account whose tokens will be burned.
@param _value The amount that will be burned.
"""
assert _to != empty(address)
self.totalSupply -= _value
self.balanceOf[_to] -= _value
log Transfer(_to, empty(address), _value)


@external
def burn(_value: uint256):
"""
@dev Burn an amount of the token of msg.sender.
@param _value The amount that will be burned.
"""
self._burn(msg.sender, _value)


@external
def burnFrom(_to: address, _value: uint256):
"""
@dev Burn an amount of the token from a given account.
@param _to The account whose tokens will be burned.
@param _value The amount that will be burned.
"""
self.allowance[_to][msg.sender] -= _value
self._burn(_to, _value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@external
def mint(_to: address, _value: uint256):
"""
@dev Mint an amount of the token and assigns it to an account.
This encapsulates the modification of balances such that the
proper events are emitted.
@param _to The account that will receive the created tokens.
@param _value The amount that will be created.
"""
assert msg.sender == self.minter
assert _to != empty(address)
self.totalSupply += _value
self.balanceOf[_to] += _value
log Transfer(empty(address), _to, _value)
@internal
def _burn(_to: address, _value: uint256):
"""
@dev Internal function that burns an amount of the token of a given
account.
@param _to The account whose tokens will be burned.
@param _value The amount that will be burned.
"""
assert _to != empty(address)
self.totalSupply -= _value
self.balanceOf[_to] -= _value
log Transfer(_to, empty(address), _value)
@external
def burn(_value: uint256):
"""
@dev Burn an amount of the token of msg.sender.
@param _value The amount that will be burned.
"""
self._burn(msg.sender, _value)
@external
def burnFrom(_to: address, _value: uint256):
"""
@dev Burn an amount of the token from a given account.
@param _to The account whose tokens will be burned.
@param _value The amount that will be burned.
"""
self.allowance[_to][msg.sender] -= _value
self._burn(_to, _value)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

Comment on lines +32 to +41
# Check for `implements`
is_implemented = (
len(
ast.get_descendants(
vy_ast.AnnAssign,
{"target.id": "implements", "annotation.id": interface_name},
)
)
> 0
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the "implements: interface" check (+ a more pythonic way of checking for a non empty list):

Suggested change
# Check for `implements`
is_implemented = (
len(
ast.get_descendants(
vy_ast.AnnAssign,
{"target.id": "implements", "annotation.id": interface_name},
)
)
> 0
)
# Check for `implements`
is_implemented = bool(
ast.get_descendants(vy_ast.nodes.ImplementsDecl, {"annotation.id": interface_name})
)

)

# Check for usage as `Interface(address).function()`
is_used = len(ast.get_descendants(vy_ast.Call, {"func.id": interface_name})) > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is_used = len(ast.get_descendants(vy_ast.Call, {"func.id": interface_name})) > 0
is_used = bool(ast.get_descendants(vy_ast.Call, {"func.id": interface_name}))

@BoboTiG
Copy link
Contributor

BoboTiG commented Jul 12, 2023

I'll have a second patch to improve performances in all analysis files, but will open a separate PR for that.

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.

2 participants