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

#86dtfv7aw - Error when compiling smart contract with custom class th… #1259

Merged
merged 1 commit into from
May 28, 2024

Conversation

luc10921
Copy link
Contributor

…at has a method that returns an explicitly typed dict

Summary or solution description
An error was being thrown when using an attribute inside a dict and typing the dict in the return.

How to Reproduce

from typing import Any
from boa3.builtin.compile_time import public
class Example:
def __init__(self, shape: str, color: str, background: str, size: str):
self.shape = shape
self.color = color
self.background = background
self.size = size
def test_value(self) -> dict[str, str]:
return {
'shape': self.shape,
'color': self.color,
'background': self.background,
'size': self.size
}
def test_keys(self) -> dict[str, str]:
return {
self.shape: 'shape',
self.color: 'color',
self.background: 'background',
self.size: 'size'
}
def test_pair(self) -> dict[str, str]:
return {
self.shape: self.shape,
self.color: self.color,
self.background: self.background,
self.size: self.size
}
@public
def test_only_values() -> Any:
example = Example('Rectangle', 'Blue', 'Black', 'Small')
return example.test_value()
@public
def test_only_keys() -> Any:
example = Example('Rectangle', 'Blue', 'Black', 'Small')
return example.test_keys()
@public
def test_pair() -> Any:
example = Example('Rectangle', 'Blue', 'Black', 'Small')
return example.test_pair()

Tests

async def test_return_dict_with_class_attributes(self):
await self.set_up_contract('ReturnDictWithClassAttributes.py')
expected_result = {
'shape': 'Rectangle',
'color': 'Blue',
'background': 'Black',
'size': 'Small'
}
result, _ = await self.call('test_only_values', [], return_type=dict[str,str])
self.assertEqual(expected_result, result)
expected_result = {
'Rectangle': 'shape',
'Blue': 'color',
'Black': 'background',
'Small': 'size'
}
result, _ = await self.call('test_only_keys', [], return_type=dict[str,str])
self.assertEqual(expected_result, result)
expected_result = {
'Rectangle': 'Rectangle',
'Blue': 'Blue',
'Black': 'Black',
'Small': 'Small'
}
result, _ = await self.call('test_pair', [], return_type=dict[str,str])
self.assertEqual(expected_result, result)

Platform:

  • OS: Windows 11 x64
  • Python version: Python 3.11

…at has a method that returns an explicitly typed dict
@luc10921 luc10921 requested a review from meevee98 May 27, 2024 14:02
@luc10921 luc10921 self-assigned this May 27, 2024
@coveralls
Copy link
Collaborator

Coverage Status

coverage: 91.195% (+0.001%) from 91.194%
when pulling a2e9ac5 on CU-86dtfv7aw
into 504b102 on development.

@meevee98 meevee98 merged commit 27dc315 into development May 28, 2024
5 checks passed
@meevee98 meevee98 deleted the CU-86dtfv7aw branch May 28, 2024 18:26
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.

4 participants