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

Updated Ypy API for new Yrs version #16

Merged
merged 11 commits into from
Mar 28, 2022
Merged

Updated Ypy API for new Yrs version #16

merged 11 commits into from
Mar 28, 2022

Conversation

Waidhoferj
Copy link
Collaborator

@Waidhoferj Waidhoferj commented Mar 20, 2022

Updated libraries and adapted Ypy API to be more Pythonic. The goal of the latter is to make Y types as interoperable as possible with native Python data structures without causing confusion.

Changes

Package Updates

  • Updated PyO3 to 0.16.2
  • Updated Yrs to 0.5.0

Rust Ypy methods:

  • Added trait Iterator to several internal type iterators for clarity
  • Took out YTransaction argument for all read-only functions.

YArray

Added native support for:

  • Iteration: [el for el in y_array]
  • Contains: el in y_array
  • Number indexing: y_array[0]
  • Range indexing: y_array[1:3]
  • String [1,2,3] and Repr YArray([1,2,3]) outputs for printing.
  • Length operator len(y_array)

YMap

  • Key Iteration: [key for key in y_map]
  • Key/Value iteration changed from entries() to items() to match Python dictionary API
  • Contains: key in y_map
  • Key indexing: y_map["key"]
  • String {"key": "value"} and Repr YMap({"key": "value"}) outputs for printing.
  • Length operator len(y_map)

YText

  • Character Iteration: [c for c in y_text]
  • Contains: substring in y_text
  • String "hello" and Repr YText("hello") outputs for printing.
  • Length operator len(y_text)

I recommend adding character and range indexing in another PR. The other option would just be converting first and then operating on the string:

# with direct indexing
y_text[0:3] # does string casting and iteration internally

# Using the str method instead
string = str(y_text)
string[0:3]

YXml Types

Made the following methods into getters:

  • first_child: Optional[Xml]
  • next_sibling: Optional[Xml]
  • prev_sibling: Optional[Xml]
  • parent: Optional[YXmlElement]

Added String an Repr methods similar to the ones above.

Testing

Updated tests to handle new functionality

Documentation

Updated docstrings and type hints for all methods

@Waidhoferj Waidhoferj added the enhancement New feature or request label Mar 20, 2022
@Waidhoferj Waidhoferj requested review from dmonad and a team March 20, 2022 02:08
@Waidhoferj Waidhoferj self-assigned this Mar 20, 2022
src/y_array.rs Show resolved Hide resolved
src/y_text.rs Outdated Show resolved Hide resolved
src/y_text.rs Outdated Show resolved Hide resolved
src/y_array.rs Outdated Show resolved Hide resolved
src/y_array.rs Outdated Show resolved Hide resolved
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.

3 participants