A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2006-January/059764.html below:

[Python-Dev] basenumber redux

[Python-Dev] basenumber reduxNick Coghlan ncoghlan at gmail.com
Mon Jan 16 10:05:24 CET 2006
Alex Martelli wrote:
> I'll be happy to draft a PEP if needed (and just as happy to  
> eventually provide an implementation patch if the PEP's accepted),  
> but wanted to doublecheck on the general issue first!

I haven't really followed the earlier basenumber discussions (aside from the 
sidetrack into the nature of mappings), but why would we want this ability as 
a typecheck and not some form of interface check?

For example, what's wrong with "hasattr(x, __int__)"? That works for all the 
builtin types, and, IMO, anyone defining a direct conversion to an integer for 
a non-numeric type deserves whatever happens to them.

Something like:

   def is_number(x):
       return hasattr(x, '__int__')

   def is_integer(x):
       return x == int(x)

Requiring inheritance from "basenumber" in order to make something behave like 
a real number seems antithetical to both duck-typing and the adaptation PEP.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4