[issue30888] import class not isinstance of the class

2017-07-17 Thread 邱伟略

邱伟略 added the comment:

ok. i see what you mean.
so python mark the class from the import way

--
resolution: not a bug -> works for me
stage:  -> resolved
status: pending -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30888] import class not isinstance of the class

2017-07-10 Thread Ronald Oussoren

Ronald Oussoren added the comment:

In foo2.py you import "a.foo", which refers to module 'a' that isn't included 
in the directory structure you describe.  I'm assuming 'dirc' should be 'a' to 
match the code.

How did you run foo1.py?  

When running with 'python3.6 -m bug.foo1' I get an error about not being able 
to import 'a' (as expected, the package is 'bug.a').

When you run with "PYTHONPATH=. python3.6 bug/foo1.py" I get the assertion 
failure you mention, and that's expected behavior.  This gets clearer when you 
print type(fun()) and Event, the output will be:

  
  

As you can see these refer to two different classes, not the same class.

The reason for this is that  'python3.6 bug/foo1.py' adds the 'bug' directory 
to the start of sys.path, hence the "import a.foo" in foo2 succeeds. The script 
foo1.py imports 'bug.a.foo', which is a different name that happens to refer to 
the same file on the filesystem.

All in all this is expected behavior and not a bug.

--
resolution:  -> not a bug
status: open -> pending

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30888] import class not isinstance of the class

2017-07-09 Thread 邱伟略

New submission from 邱伟略:

the working directory is like below:

bug/
dirc/
__init__.py
foo.py
foo2.py
__init__.py
foo1.py


in foo.py:
```
class Event(object):
pass
```

in foo2.py:
```
from a.foo import Event

def fun():
return Event()
```

in foo1.py:
```
from bug.a.foo import Event
from bug.a.foo2 import fun

assert isinstance(fun(), Event)
```

when i try to execute the code in foo1.py, i got an assertion error.

but if i change foo2.py to:
```
from ..a.foo import Event

def fun():
return Event()

```

the code in foo1.py can be done well without the assertion error.

i think it's about the import mechanism. 

i have checked pep328

I think 
when i do "from a.foo import Event", python import Event by the package name 
"a.foo.Event", but "from ..a.foo import Event" is going to import Event by 
"bug.a.foo.Event". and it is totally different in python.

is it kind of bug python should prevent?

--
components: macOS
messages: 298018
nosy: ned.deily, ronaldoussoren, 邱伟略
priority: normal
severity: normal
status: open
title: import class not isinstance of the class
type: behavior
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com