mswart / pyopenmensa

Python wrapper and helper for openmensa api and feed
http://pyom.devtation.de/
GNU Lesser General Public License v3.0
9 stars 7 forks source link

feed: make price typecheck less strict #3

Closed cyroxx closed 10 years ago

cyroxx commented 10 years ago

The price conversion is now able to deal with subclasses of int, float, str and not only the exact types.

This gives greater flexibility when working with subclasses, as you do not have to explicitly convert to the corresponding supertype.

mswart commented 10 years ago

Do you have an example in which the strict checks are an issue - for now I can only think about cases where int or str is subclassed. It would be good if you would add this directly as tests, so it will not again broken in the future.

cyroxx commented 10 years ago

You are completely right, this is an issue if you have subclasses of the built-in types at hand. However, I think it is not necessary to strictly enforce the exact type in those cases addresses by this PR.

An example comes from working with BeautifulSoup: There you have the str subclass NavigableString. Although this class behaves pretty much the same as a plain string, I had to convert my price instances using str(myprice) before I could throw them to convertPrice/buildPrices. This should not be mandatory since they are children of str in the inheritance tree.

mswart commented 10 years ago

Released as 0.91.0