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
Eliminate make_iter by eliminating the reason for it #1154
Comments
It should be sufficient as you say, when only one element is expected, to return only that one element or raise an exception -- or call another method and always get a list with none, one, or many elements whereby instead of coding to process the possible data types, the only processing needed is to count the elements of the returned list before operating on it. |
While I agree with the general notion of this, it is a big enough API change that it should go into a future dev branch with other API changes building up to Evennia 0.7. |
I wonder if it may be better to, rather than have two methods with different expected results, just have one and always return a list from it with 0, 1 or more elements. Since that's similar to our |
See #1154. In the end I didn't modify the Attributehandler and TagHandler like this, instead I added the `return_list` argument for cases when one wants a guaranteed return.
@Kelketek I reworked handlers a bit on |
This will close when devel merges. |
Closed with the merger of |
Brief summary of issue / Description of requested feature:
Several database querying methods can return either a single object or a list of objects depending on how many are returned. This creates issues when trying to reason about the types returned by the function, and requires something like
make_iter
to fix it, but it does not truly do so.make_iter
creates more boilerplate than it removes, and there are more clear ways to do the same thing.Steps to reproduce the issue / Reasons for adding feature:
Take this example code:
my_tags
could be:These are three different types, all of which must be handled. Here's some boilerplate code that would handle it:
At this point, I can now safely iterate over the list. If I just wanted the first item, I could do:
You will note, however, that this precisely undoes and redoes what the special casing at the end of
get
methods tries to solve, namely, to only send back one object if it's found. The alternative is to do something like this:Error output / Expected result of feature
My preference would be to have two methods where one is currently being used, both with different expectations on what's needed.
Extra information, such as Evennia revision/repo/branch, operating system and ideas for how to solve / implement:
One could be
filter
orquery
or something, and it would imply that a list is always returned. The other would beget
, which would just be a wrapper around the other method where it tries to grab a single item, and raises an error if there's more than one or if there isn't any.The text was updated successfully, but these errors were encountered: