-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add Path.from_parts()
or similar to allow tuple constructor like pathlib.Path
#157
Comments
I suggest 2 possible approaches:
*: By "tuple" it should actually mean "any sequence which is not an string", so lists and similar iterables are allowed too. anyway, that's a minor detail. |
Right, so now I see why you wanted to concatenate ints too. But in this case subscripting is the operation you would want anyway. Assuming Anyway, I agree that path = tuple.__new__(Path, (NamedKey(k) if isinstance(k, str) else ListIndex(k) for k in data.keys[:-1])) Also a |
Yeah, but since it came from a tuple, using a method called
The operations semantically are different, I agree, but For example, let's say we hypothetically allow tuples/lists in
|
in this scenario, |
Hum, didn't know about
Feel free to grab my |
Yup sorry if this wasn't really clear, the first paragraph wasn't really related to I'm completely on board with |
Nah, you were clear enough I could infer you approved
Yeah, I carefully chose to use indexing instead of concatenation in
Well... I didn't PR this one yet... will do so in the next days |
Right, makes sense!
By "patches" I was actually referring to your |
I have this NBT Explorer-like printing and when re-implementing it using my generic tree walker I noticed a missing feature in
Path
that forced me to use a really inefficient constructor:The generic tree walker yields a generic
tuple
containing each path component, similar to thepathlib.Path()
API. And to create annbtlib.Path
from this tuple I had to resort to an expensive that iteratively (or recursively) creates a newPath
for each component by concatenating the next component (def get_element(root, keys): return get_element(root[keys[0]], keys[1:]
). (by the way, this concatenation is what led me to #146 , as each part can be anint
(forList
) orstr
(forCompound
)I'm sure there are better, or at least easier ways of doing this. Something like
Path.from_accessors()
, but skipping the parser by assuming each part is either anint
or astr
representing a single key.The text was updated successfully, but these errors were encountered: