Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101876 > unrolled thread

When is an int not an int? Who can explain this?

Started by"Charles T. Smith" <cts.private.yahoo@gmail.com>
First post2016-01-18 16:11 +0000
Last post2016-01-19 04:35 +1100
Articles 7 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  When is an int not an int?  Who can explain this? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-18 16:11 +0000
    Re: When is an int not an int? Who can explain this? Chris Angelico <rosuav@gmail.com> - 2016-01-19 03:19 +1100
      Re: When is an int not an int? Who can explain this? "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2016-01-18 16:28 +0000
        Re: When is an int not an int? Who can explain this? Chris Angelico <rosuav@gmail.com> - 2016-01-19 03:51 +1100
        Re: When is an int not an int? Who can explain this? Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-18 10:00 -0700
        Re: When is an int not an int? Who can explain this? Random832 <random832@fastmail.com> - 2016-01-18 12:02 -0500
        Re: When is an int not an int? Who can explain this? Chris Angelico <rosuav@gmail.com> - 2016-01-19 04:35 +1100

#101876 — When is an int not an int? Who can explain this?

From"Charles T. Smith" <cts.private.yahoo@gmail.com>
Date2016-01-18 16:11 +0000
SubjectWhen is an int not an int? Who can explain this?
Message-ID<n7j2r0$hc4$1@dont-email.me>
$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> type(0) is int
True
...
(PDB)type(0) is int
False
(PDB)type(1) is int
False

(PDB)p 5 + 0
5

(PDB)class c (object): pass
(PDB)type (c()) is c
True


[toc] | [next] | [standalone]


#101877 — Re: When is an int not an int? Who can explain this?

FromChris Angelico <rosuav@gmail.com>
Date2016-01-19 03:19 +1100
SubjectRe: When is an int not an int? Who can explain this?
Message-ID<mailman.89.1453134008.15297.python-list@python.org>
In reply to#101876
On Tue, Jan 19, 2016 at 3:11 AM, Charles T. Smith
<cts.private.yahoo@gmail.com> wrote:
> $ python
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> type(0) is int
> True
> ...
> (PDB)type(0) is int
> False
> (PDB)type(1) is int
> False

Possibility #1: 'int' has been rebound.

Possibility #2: 'type' has been rebound.

I'd check them in that order.

ChrisA

[toc] | [prev] | [next] | [standalone]


#101878 — Re: When is an int not an int? Who can explain this?

From"Charles T. Smith" <cts.private.yahoo@gmail.com>
Date2016-01-18 16:28 +0000
SubjectRe: When is an int not an int? Who can explain this?
Message-ID<n7j3s1$hc4$2@dont-email.me>
In reply to#101877
On Tue, 19 Jan 2016 03:19:59 +1100, Chris Angelico wrote:

> On Tue, Jan 19, 2016 at 3:11 AM, Charles T. Smith
> <cts.private.yahoo@gmail.com> wrote:
>> $ python
>> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> type(0) is int
>> True
>> ...
>> (PDB)type(0) is int
>> False
>> (PDB)type(1) is int
>> False
> 
> Possibility #1: 'int' has been rebound.
> 
> Possibility #2: 'type' has been rebound.
> 
> I'd check them in that order.
> 
> ChrisA


But:

(PDB)p 5 + 0
5

(PDB)class c (object): pass
(PDB)type (c()) is c
True

Okay, I think I understand it now:

(PDB)type (int)
<type 'module'>

(PDB)type (float)
<type 'type'>

[toc] | [prev] | [next] | [standalone]


#101879 — Re: When is an int not an int? Who can explain this?

FromChris Angelico <rosuav@gmail.com>
Date2016-01-19 03:51 +1100
SubjectRe: When is an int not an int? Who can explain this?
Message-ID<mailman.90.1453135892.15297.python-list@python.org>
In reply to#101878
On Tue, Jan 19, 2016 at 3:28 AM, Charles T. Smith
<cts.private.yahoo@gmail.com> wrote:
> On Tue, 19 Jan 2016 03:19:59 +1100, Chris Angelico wrote:
>> Possibility #1: 'int' has been rebound.
>>
>> Possibility #2: 'type' has been rebound.
>>
>> I'd check them in that order.
>>
>> ChrisA
>
>
> But:
>
> (PDB)p 5 + 0
> 5

That shows that your literals haven't changed. They basically never
will (barring *really* crazy shenanigans).

> (PDB)class c (object): pass
> (PDB)type (c()) is c
> True

And this shows that the name 'type' probably hasn't changed. It's
still possible that it's not the normal 'type' type, but far more
likely that it's 'int' that got rebound, which is why I suggested
checking for that first.

> Okay, I think I understand it now:
>
> (PDB)type (int)
> <type 'module'>
>
> (PDB)type (float)
> <type 'type'>

And that's pretty strong evidence right there! So the next question
is... what got imported under the name 'int'?

int.__name__ will be a start. If that just returns the string 'int',
then try int.__package__ which might give a hint. Also, int.__file__
will tell you where it was loaded from, if it was indeed loaded from a
file.

Armed with that information, you should be able to track down what's
going on. It's curious, though, that you have a callable subclass of
module bound to the name int. Very curious indeed.

ChrisA

[toc] | [prev] | [next] | [standalone]


#101881 — Re: When is an int not an int? Who can explain this?

FromIan Kelly <ian.g.kelly@gmail.com>
Date2016-01-18 10:00 -0700
SubjectRe: When is an int not an int? Who can explain this?
Message-ID<mailman.92.1453136470.15297.python-list@python.org>
In reply to#101878
On Mon, Jan 18, 2016 at 9:51 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Tue, Jan 19, 2016 at 3:28 AM, Charles T. Smith
>> Okay, I think I understand it now:
>>
>> (PDB)type (int)
>> <type 'module'>
>>
>> (PDB)type (float)
>> <type 'type'>
>
> And that's pretty strong evidence right there! So the next question
> is... what got imported under the name 'int'?
>
> int.__name__ will be a start. If that just returns the string 'int',
> then try int.__package__ which might give a hint. Also, int.__file__
> will tell you where it was loaded from, if it was indeed loaded from a
> file.
>
> Armed with that information, you should be able to track down what's
> going on. It's curious, though, that you have a callable subclass of
> module bound to the name int. Very curious indeed.

What makes you think that it's a callable subclass? I don't see any
place in the posted transcript where int has been called.

[toc] | [prev] | [next] | [standalone]


#101882 — Re: When is an int not an int? Who can explain this?

FromRandom832 <random832@fastmail.com>
Date2016-01-18 12:02 -0500
SubjectRe: When is an int not an int? Who can explain this?
Message-ID<mailman.93.1453136552.15297.python-list@python.org>
In reply to#101878
On Mon, Jan 18, 2016, at 11:51, Chris Angelico wrote:
> Armed with that information, you should be able to track down what's
> going on. It's curious, though, that you have a callable subclass of
> module bound to the name int. Very curious indeed.

He hasn't tried calling it. And there's no reason to assume it is a
subclass. The results he's shown imply that the object bound to the name
int is an instance of a type named module* (which is almost certainly,
but not definitely, the usual module type itself, and no more likely to
be a subclass of it than of anything else.)

*Strictly speaking, a type whose repr is "<class 'module'>"

[toc] | [prev] | [next] | [standalone]


#101883 — Re: When is an int not an int? Who can explain this?

FromChris Angelico <rosuav@gmail.com>
Date2016-01-19 04:35 +1100
SubjectRe: When is an int not an int? Who can explain this?
Message-ID<mailman.94.1453138559.15297.python-list@python.org>
In reply to#101878
On Tue, Jan 19, 2016 at 4:00 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>> Armed with that information, you should be able to track down what's
>> going on. It's curious, though, that you have a callable subclass of
>> module bound to the name int. Very curious indeed.
>
> What makes you think that it's a callable subclass? I don't see any
> place in the posted transcript where int has been called.

Oops, my bad. I thought he'd called int(5) in his original demo. So,
yeah, it's just a module. (Or, as Random832 points out, it's something
with that repr. But probably a module.) Strike that bit about it being
callable.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web