Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Path cannot add or init integers, only strings and other Paths #146

@MestreLion

Description

@MestreLion

Path.__add__() (and __radd__), as well as __init__(), accepts str and Path, but not int. Considering it can handle ints just fine in subscriptors, why not add support for + too?

Currently we have:

Path("a")["b"]["c"] == Path("a.b.c")
"a" + Path("b") + "c" == Path("a.b.c")
Path("a")[1]["c"] == Path("a[1].c")
Path("[0]")[1]["c"] == Path("[0][1].c")

It could also allow the following:

"a" + Path("[1]") + "b" + 2 == Path("a[1].b[2]")
0 + Path("b") + 1 == Path("[0].b[1]")
0 + Path()[1] + 2 == Path("[0][1][2]")
"a" + Path(1)["b"] + Path(3)[4] + 5 + "c" == Path("a[1].b[3][4][5].c")

I could send a PR if you approve the idea

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions