Skip to content

[Question] How to implement object methods? #10

Description

@bbrodriges

I want to try to implement hashlib (PR will follow).

For now I have implemented Type, module, module method and some "magic methods", but I cannot figure out how to implement object methods such as update, hexdigest etc.

Here is my WIP implementation.

Thanks in advance.

Activity

  1. changed the title [-]How to implement object methods?[/-] [+][Question] How to implement object methods?[/+] on Aug 23, 2018
  2. ncw commented on Aug 28, 2018

    @ncw
    Collaborator

    This isn't particularly elegant at the moment, but see py/generator.go for an example. You basically add the method objects to the type's Dict by hand.

    	GeneratorType.Dict["send"] = MustNewMethod("send", func(self Object, value Object) (Object, error) {
    		return self.(*Generator).Send(value)
    	}, 0, "send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")
  3. added
    questionFurther information is requested
    on Aug 28, 2018
  4. drew-512 commented on Feb 22, 2022

    @drew-512
    Contributor

    recommend @sbinet close -- addressed w/ #163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions