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

Modified IndefiniteList as subclass of UserList. #138

Merged
merged 2 commits into from Dec 2, 2022

Conversation

bhatt-deep
Copy link
Contributor

To facilitate different list functionalities like append, pop, extend etc. in IndefiniteList, have implemented the IndefiniteList as a subclass of UserList from collections.

@cffls
Copy link
Collaborator

cffls commented Nov 30, 2022

Thanks! It is a great idea to use UserList. The code looks good to me. There are some errors in static type check. Once those are fixed, this PR should be good to go.

pycardano/serialization.py Outdated Show resolved Hide resolved
pycardano/serialization.py Outdated Show resolved Hide resolved
@bhatt-deep
Copy link
Contributor Author

@cffls I have updated the value.data to value. Then I was looking at the static types, The error is due to None type in Initlist of init method in UserList and we provide the Primitive types in the method while we call IndefiniteList,
But need some suggestions on how to deal with this.
attaching the relevant code parts here.

class UserList(_collections_abc.MutableSequence):
   A more or less complete user-defined wrapper around list objects.

   def __init__(self, initlist=None):
       self.data = []
       if initlist is not None:
           # XXX should this accept an arbitrary sequence?
           if type(initlist) == type(self.data):
               self.data[:] = initlist
           elif isinstance(initlist, UserList):
               self.data[:] = initlist.data[:]
           else:
               self.data = list(initlist)

and https://github.com/Python-Cardano/pycardano/blob/main/pycardano/serialization.py#L422-L427

@cffls
Copy link
Collaborator

cffls commented Dec 2, 2022

@cffls I have updated the value.data to value. Then I was looking at the static types, The error is due to None type in Initlist of init method in UserList and we provide the Primitive types in the method while we call IndefiniteList, But need some suggestions on how to deal with this. attaching the relevant code parts here.

class UserList(_collections_abc.MutableSequence):
   A more or less complete user-defined wrapper around list objects.

   def __init__(self, initlist=None):
       self.data = []
       if initlist is not None:
           # XXX should this accept an arbitrary sequence?
           if type(initlist) == type(self.data):
               self.data[:] = initlist
           elif isinstance(initlist, UserList):
               self.data[:] = initlist.data[:]
           else:
               self.data = list(initlist)

and https://github.com/Python-Cardano/pycardano/blob/main/pycardano/serialization.py#L422-L427

I guess the problem is that UserList is not using typehint. Maybe try creating a init method for IndefiniteList and ignore the type check when passing the value.

class IndefiniteList(UserList):
    
    def __init__(list: List[Primitive]): # type: ignore
        super().__init__(list)

@cffls cffls merged commit 1db3a57 into Python-Cardano:main Dec 2, 2022
@cffls cffls added the enhancement New feature or request label Dec 3, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants