jacebrowning / yorm

Automatic object-YAML mapping for Python.
https://yorm.readthedocs.io
MIT License
27 stars 6 forks source link

Implement match() #143

Closed AstraLuma closed 7 years ago

AstraLuma commented 7 years ago

Add the ability to search for objects, given filename-keyed values.

Implements #123.

AstraLuma commented 7 years ago

So it turns out, this quickly explodes in complexity.

The huge problem is what to do with __init__(), since different classes will have different calling conventions. And if any user created a class that doesn't save information necessary to construct it, we're SoL.

It crossed my mind to manually call __new__() and __init__(), but 1. That feels like asking for trouble, and 2. We still don't know how to call either if they got overridden.

jacebrowning commented 7 years ago

since different classes will have different calling conventions. And if any user created a class that doesn't save information necessary to construct it

Yeah, one of the goals of YORM (which I think makes it appealing) is that it should work on any class without modification.

Perhaps match() needs to take some sort of factory object that know how to construct the type of object the user is looking for (including knowing which arguments do not influence the resulting file path)?

AstraLuma commented 7 years ago

Is there a preferred place to keep the path_format?

jacebrowning commented 7 years ago

Is there a preferred place to keep the path_format?

Currently nothing is stored on the class objects. The attribute mappings are stored in yorm.common.attrs[cls]. Perhaps there could be yorm.common.path_formats[cls]? If path_format is to be saved, I'd rather see these combined into a "mappings" dictionary containing all of the class's metadata.

AstraLuma commented 7 years ago

I would much rather save the path_format and give users convenient DRY options.

AstraLuma commented 7 years ago

I didn't want to have to refactor a bunch of unrelated code in order to implement this. Unless you feel strongly about having them in the same mapping.

AstraLuma commented 7 years ago

How should I handle the pylint errors? I want to ignore a bunch of them, and there's a bunch in code i didn't touch.

jacebrowning commented 7 years ago

I'll add Python 3.6 support and pin pylint in another PR.

AstraLuma commented 7 years ago

I think this is ready for review.

AstraLuma commented 7 years ago

... I have no idea what to do with the E1101 since I'm pretty sure it's full of it. (parse leaves compile() out of __all__ on purpose.)

jacebrowning commented 7 years ago

Weird that it's only breaking on Python 3.5. We can just add no-member to the list of disabled rules. That rule is unlikely to catch anything that wouldn't be caught by reasonable test coverage.