Dear Tibor,
something like:
class BibRecDocs:
def __init__(self, recid, deleted_too=False, human_readable=False):
try:
self.id = int(recid)
except ValueError:
raise ValueError("Invalid input parameter")
can be a good solution.
The actual code do not complain for a string input parameter, thus I got an
exception later in my code, during the BibDocFile.__repr__ call with an
unclear message, and I did not know why.
Note: for BibRecDocs.__repr__, the recid is formatted by a "%s" and, for the
BibDocFile.__repr__, the recid is formatted by a "%i", perhaps this can be
unified.
Best regards,
----------------------------------------------------------------------
Johnny Mariéthoz
RERO, Av. de la Gare 45, CH - 1920 MARTIGNY
Téléphone: +41(0)27 721 8579
Fax : +41(0)27 721 8586
Web : http://www.rero.ch
ReroDoc : http://doc.rero.ch, [email protected]
----------------------------------------------------------------------
Le 13 juin 2012 à 15:15, Tibor Simko a écrit :
> On Fri, 08 Jun 2012, Johnny Mariéthoz wrote:
>> Perhaps a good fix is to check the type of the input parameter and
>> generate a comprehensive exception.
>
> Hmm, BibRecDocs's documentation does mention that `recid' should be an
> integer, so that's perhaps enough.
>
> Do you meant to check type already in the constructor so as not to
> permit the following?
>
> In [4]: BibRecDocs('10').list_bibdocs()
> Out[4]: [BibDoc(14, '10', 'ep-2001-094', 'Main', False)]
>
> In [5]: BibRecDocs(10).list_bibdocs()
> Out[5]: [BibDoc(14, 10, 'ep-2001-094', 'Main', False)]
>
> Or do you mean to accept both str and int in the constructor and amend
> only __repr__?
>
> I guess we'd rather forbid the former and take an int out of str
> in case the type transform cleanly.
>
> Best regards
> --
> Tibor Simko