Pagination: Give the InvalidPage exception an attribute storing the converted integer number
|Reported by:||miracle2k||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
This truly is a tiny issue, but when subclassing Paginator, if you override page(), there are different things that can happen:
- Page number is valid, you get a Page object.
- Page number is out of range, InvalidPage is raised
- Page number is not a number, InvalidPage is raised
In your child class, you cannot differ between 1) and 2/3), so if you want to work with "number" afterwards, you once again need to check it's an int, and raise the appropriate exceptions if not.
Suggestioned solution: Give the InvalidPage exception a number field that is set whenever the number was successfully converted to an integer.
class MyPaginator(Pagintor): def page(self, number): try: super(MyPaginator, self).page(number) except InvalidPage, e: # using "number" here is problematic - it might be a string if e.number > self.num_pages: # ...