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

WIP: class based api #173

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

WIP: class based api #173

wants to merge 1 commit into from

Conversation

slavikovbasa
Copy link
Collaborator

Added type conversions (built-ins -> hiku types), as the first step of class-based API implementation.

For now covering built-in scalars (int, float, bool, str) + containers (list, optional) + typerefs for custom object types. With the refs to python classes cyclic imports become a real problem, so I added lazy annotation for that purpose (influenced by strawberry). I was not too concerned about python versioning so far - I will use proper typing_extension imports and so on after the basic stuff is ready and working.

My main concern is being able to gradually update existing definitions with class-based API - for that purpose raw_type annotation was added. Basically raw_type could be all we need to start writing classes, though typing.Annotated stuff does look cumbersome - that's why I decided to cover some basic cases (scalars, containers, typerefs) too. Interfaces, unions, enums, custom scalars (including hiku.types.ID and hiku.types.Any) for now require the use of raw_type. Later there should be no problems implementing interfaces via class inheritance, unions and custom scalars via type aliases, enums - using enum stdlib.

For the next step, I plan to add transformations of class-based nodes to hiku.graph.Node. I believe, that it should go to Graph.__init__: lazy imports should be able to resolve just fine there (cuz all nodes have to be imported anyway to be passed to Graph.items). During transformation I plan to auto-transform field names to camelCase and add some default resolvers, all other params unchanged for now.

@slavikovbasa
Copy link
Collaborator Author

I am open to the discussion on everything - naming, algorithms, ideas and so on

@slavikovbasa slavikovbasa self-assigned this Oct 20, 2024
@kindermax
Copy link
Collaborator

Overall this looks like a good starting point. Lets go with this and see where it goes.

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