[issue10073] calendar.isleap() not checking parameter type
Georg Brandl
report at bugs.python.org
Fri Oct 15 22:51:17 CEST 2010
Georg Brandl <georg at python.org> added the comment:
> To me, Alexander's example
> >>> calendar.isleap("%d")
> False
> is a buggy result. So I would reclassify the issue.
You'll always find plenty "wrong" inputs for which a function doesn't
raise an exception. That's the downside of duck typing.
> The rationale for not checking input types is that bad types result
> in an error, but that does not happen here due to a design decision
> that some consider clever and some buggy, and some both. (Guido
> himself would like to deprecate it.)
You're talking of % string formatting? Well, that's just one operation
where duck typing applies. There may be a bit less chance of namespace
collisions when calling methods, but it's the same issue at heart.
> I am in favor of the 'year & 3 == 0' fix so that any input string
> (and indeed, anything that does not implement both % and & operators)
> raises an error. Intermediate to expert programmers should know or
> learn about bit masking. Add a comment to explain the reason -- and
> a test case.
I agree that ``year & 3 == 0`` in this place is okay, and if it helps
avoid confusion, all the better.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10073>
_______________________________________
More information about the Python-bugs-list
mailing list