[issue42273] Using LazyLoader leads to AttributeError

2020-11-10 Thread Kevin Keating


Kevin Keating  added the comment:

One possible solution here would be to update the documentation at 
https://github.com/python/cpython/blob/master/Doc/library/importlib.rst#implementing-lazy-imports
 to either note the limitation or to modify the lazy_import function so that it 
adds the module to the package's namespace.  That's basically the workaround 
that we've been using.

--

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



[issue42273] Using LazyLoader leads to AttributeError

2020-11-10 Thread Kevin Keating


Kevin Keating  added the comment:

Brett, what do you mean by "the way import works"?  Is the difference between 
using LazyLoader and using a normal import intentional?

--
status:  -> open

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



[issue42273] Using LazyLoader leads to AttributeError

2020-11-09 Thread Kevin Keating


Kevin Keating  added the comment:

My colleague just tested this on Mac and confirms that the bug also occurs 
there using Python 3.8.3.

--

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



[issue42273] Using LazyLoader leads to AttributeError

2020-11-09 Thread Kevin Keating


Kevin Keating  added the comment:

An __init__.py shouldn't be necessary.  If I comment out the 'b = 
lazy_import("foo.b")' line in a.py (i.e. disable the lazy import), then the 
print statement works correctly as written without any other changes.

Also, I double checked with the colleague who originally ran into this issue, 
and it turns out he encountered the bug on Linux, not on Mac (still Python 
3.8.3).

--

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



[issue42273] Using LazyLoader leads to AttributeError

2020-11-05 Thread Kevin Keating


New submission from Kevin Keating :

Steps to reproduce:

Create the following three files (or download the attached zip file, which 
contains these files):

main.py

import foo
from foo import a
from foo import b

print(foo.b.my_function())


foo/a.py

import importlib.util
import sys

# implementation copied from 
https://github.com/python/cpython/blob/master/Doc/library/importlib.rst#implementing-lazy-imports
def lazy_import(name):
spec = importlib.util.find_spec(name)
loader = importlib.util.LazyLoader(spec.loader)
spec.loader = loader
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
loader.exec_module(module)
return module

b = lazy_import("foo.b")


foo/b.py

def my_function():
return "my_function"

and then run main.py



Expected results

my_function should be printed to the terminal


Actual results

The following traceback is printed to the terminal

Traceback (most recent call last):
  File "F:\Documents\lazy_import\main.py", line 6, in 
print(foo.b.my_function())
AttributeError: module 'foo' has no attribute 'b'

If you comment out "from foo import a" from main.py, then the traceback doesn't 
occur and my_function gets printed.  Alternatively, if you move "from foo 
import a" after "from foo import b", then the traceback doesn't occur and 
my_function gets printed.  Adding "foo.b = b" before 
"print(foo.b.my_function())" will also fix the traceback.


A colleague of mine originally ran into this bug when writing unit tests for 
lazily imported code, since mock.patch("foo.b.my_function") triggers the same 
AttributeError.  I've reproduced this on Windows using both Python 3.8.3 and 
Python 3.9.0, and my colleague was using Python 3.8.3 on Mac.

--
components: Library (Lib)
files: lazy_import.zip
messages: 380437
nosy: KevKeating
priority: normal
severity: normal
status: open
title: Using LazyLoader leads to AttributeError
versions: Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49574/lazy_import.zip

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



[issue30725] Windows installer for 2.7.13 doesn't install pip when installing to C:\Program Files

2017-06-22 Thread Kevin Keating

Kevin Keating added the comment:

Running the msi from an elevated command prompt worked.  Thanks!

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30725>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30725] Windows installer for 2.7.13 doesn't install pip when installing to C:\Program Files

2017-06-22 Thread Kevin Keating

Kevin Keating added the comment:

Yeah, I only run into this problem if I install Python 2.7.13 into C:\Program 
Files\Python27.  If I install Python 2.7.12 or 3.6.1 to the same location, then 
everything works fine.  I can successfully install Python 2.7.13 to 
C:\Python27, C:\Programs\Python27, or "C:\Path with spaces\Python27".

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30725>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30725] Windows installer for 2.7.13 doesn't install pip when installing to C:\Program Files

2017-06-22 Thread Kevin Keating

Kevin Keating added the comment:

Here's the log file.  I'm assuming that the relevant bit starts at around line 
18663:

CAQuietExec:  Collecting setuptools
CAQuietExec:  Collecting pip
CAQuietExec:  Installing collected packages: setuptools, pip
CAQuietExec:  Exception:
CAQuietExec:  Traceback (most recent call last):
CAQuietExec:File 
"c:\users\keating\appdata\local\temp\tmpcvofqv\pip-9.0.1-py2.py3-none-any.whl\pip\basecommand.py",
 line 215, in main
CAQuietExec:  status = self.run(options, args)
CAQuietExec:File 
"c:\users\keating\appdata\local\temp\tmpcvofqv\pip-9.0.1-py2.py3-none-any.whl\pip\commands\install.py",
 line 342, in run
CAQuietExec:  prefix=options.prefix_path,
CAQuietExec:File 
"c:\users\keating\appdata\local\temp\tmpcvofqv\pip-9.0.1-py2.py3-none-any.whl\pip\req\req_set.py",
 line 784, in install
CAQuietExec:  **kwargs
CAQuietExec:File 
"c:\users\keating\appdata\local\temp\tmpcvofqv\pip-9.0.1-py2.py3-none-any.whl\pip\req\req_install.py",
 line 851, in install
CAQuietExec:  self.move_wheel_files(self.source_dir, root=root, 
prefix=prefix)
CAQuietExec:File 
"c:\users\keating\appdata\local\temp\tmpcvofqv\pip-9.0.1-py2.py3-none-any.whl\pip\req\req_install.py",
 line 1064, in move_wheel_files
CAQuietExec:  isolated=self.isolated,
CAQuietExec:File 
"c:\users\keating\appdata\local\temp\tmpcvofqv\pip-9.0.1-py2.py3-none-any.whl\pip\wheel.py",
 line 345, in move_wheel_files
CAQuietExec:  clobber(source, lib_dir, True)
CAQuietExec:File 
"c:\users\keating\appdata\local\temp\tmpcvofqv\pip-9.0.1-py2.py3-none-any.whl\pip\wheel.py",
 line 323, in clobber
CAQuietExec:  shutil.copyfile(srcfile, destfile)
CAQuietExec:File "C:\Program Files\Python27\lib\shutil.py", line 83, in 
copyfile
CAQuietExec:  with open(dst, 'wb') as fdst:
CAQuietExec:  IOError:  Permission denied: 'C:\\Program 
Files\\Python27\\Lib\\site-packages\\easy_install.py'

--
Added file: http://bugs.python.org/file46969/log.txt

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30725>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30725] Windows installer for 2.7.13 doesn't install pip when installing to C:\Program Files

2017-06-21 Thread Kevin Keating

New submission from Kevin Keating:

If I use the Python 64-bit 2.7.13 Windows installer and install to C:\Program 
Files\Python27, then the Scripts folder doesn't get created and pip doesn't get 
installed.  If I uninstall Python and reinstall it to C:\Python27, 
C:\Programs\Python27, or "C:\Path with spaces\Python27", then the Scripts 
folder is created and pip works correctly.  If I install Python 2.7.12 using 
https://www.python.org/ftp/python/2.7.12/python-2.7.12.amd64.msi or Python 
3.6.1 using https://www.python.org/ftp/python/3.6.1/python-3.6.1-amd64.exe, 
then I don't experience this issue.  This issue does happen if I install to 
C:\PROGRA~1\Python27, which is the 8.3 filename equivalent of C:\Program 
Files\Python27.  I've seen this on a handful of Windows 10 computers so far.  I 
haven't tried other versions of Windows or the 32-bit installers.


Steps to reproduce:
- Download the Python installer from 
https://www.python.org/ftp/python/2.7.13/python-2.7.13.amd64.msi and run it.
- Select "Install for all users" and click Next.
- Enter C:\Program Files\Python27 as the installation folder and click Next.
- Click on "Register Extensions" and select "Entire feature will be 
unavailable".  (I don't know if this step is required, but it's what I've been 
doing to test.)  Click Next.
- Click Yes at the UAC prompt.
- Wait for installation to finish.

Expected results:
The "C:\Program Files\Python27\Scripts" and "C:\Program 
Files\Python27\Lib\site-packages\pip" folders should get created during the 
installation.

Actual results:
Neither of the folders exist.

--
components: Installation, Windows
messages: 296571
nosy: KevKeating, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Windows installer for 2.7.13 doesn't install pip when installing to 
C:\Program Files
versions: Python 2.7

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30725>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22587] os.path.abspath(None) behavior is inconsistent between platforms

2014-10-10 Thread Kevin Keating

Kevin Keating added the comment:

I agree that None is an unwise value to pass in.  Of the four different abspath 
implementations, though, one will treat None (or any falsey value) as an empty 
string, while the other three will raise an exception unless passed an actual 
str or bytes object.  I think the ideal solution would be to have abspath(None) 
raise a TypeError regardless of operating system, which would make it 
consistent with normcase (http://bugs.python.org/issue9018).  It's conceivable 
that some Windows-only code might rely on the current behavior of 
abspath(None), though.

--

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



[issue22587] os.path.abspath(None) behavior is inconsistent between platforms

2014-10-09 Thread Kevin Keating

New submission from Kevin Keating:

On Windows, os.path.abspath() treats None as if it were an empty string, so 
os.path.abspath(None) returns the current working directory.  On Linux, 
os.path.abspath(None) raises an AttributeError.  With macpath, abspath(None) 
raises a TypeError.  I've seen this behavior with Python 2.7.3, 2.7.8, 3.2.5, 
and 3.4.2.

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit 
(Intel)] on win32
Type help, copyright, credits or license for more information.
 import ntpath, posixpath, macpath
 ntpath.abspath(None)
'C:\\Users\\Keating\\Documents'
 posixpath.abspath(None)
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\programs\Python34\lib\posixpath.py, line 357, in abspath
if not isabs(path):
  File C:\programs\Python34\lib\posixpath.py, line 63, in isabs
return s.startswith(sep)
AttributeError: 'NoneType' object has no attribute 'startswith'
 macpath.abspath(None)
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\programs\Python34\lib\macpath.py, line 177, in abspath
if not isabs(path):
  File C:\programs\Python34\lib\macpath.py, line 49, in isabs
return colon in s and s[:1] != colon
TypeError: argument of type 'NoneType' is not iterable

This case seems very closely related to http://bugs.python.org/issue9018, which 
noted a platform inconsistency in os.path.normcase.

--
components: Library (Lib)
messages: 228883
nosy: KevKeating
priority: normal
severity: normal
status: open
title: os.path.abspath(None) behavior is inconsistent between platforms
versions: Python 2.7, Python 3.2, Python 3.4

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



[issue22587] os.path.abspath(None) behavior is inconsistent between platforms

2014-10-09 Thread Kevin Keating

Kevin Keating added the comment:

I just realized that even the behavior of ntpath.abspath() is inconsistent 
across platforms.  On Windows, ntpath.abspath(None) returns the current working 
directory.  On other OSs, ntpath.abspath(None) raises a TypeError.  There are 
two different abspath definitions in ntpath, one that uses the native Windows 
method (used on Windows) and one that doesn't (used everywhere else).  The two 
methods behave differently if the input value isn't a string.  I've tested this 
on OS X using Python 2.7.8 and 3.4.1:

Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type help, copyright, credits or license for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
 import ntpath
 ntpath.abspath(None)
Traceback (most recent call last):
File stdin, line 1, in module
File /Users/young/anaconda/envs/py278/lib/python2.7/ntpath.py, line 473, in 
abspath
if not isabs(path):
  File /Users/young/anaconda/envs/py278/lib/python2.7/ntpath.py, line 57, in 
isabs
s = splitdrive(s)[1]
  File /Users/young/anaconda/envs/py278/lib/python2.7/ntpath.py, line 114, in 
splitdrive
if len(p)  1:
TypeError: object of type 'NoneType' has no len()


Python 3.4.1 |Anaconda 2.1.0 (x86_64)| (default, Sep 10 2014, 17:24:09) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type help, copyright, credits or license for more information.
 import ntpath
 ntpath.abspath(None)
Traceback (most recent call last):
File stdin, line 1, in module
File /Users/young/anaconda/envs/py34/lib/python3.4/ntpath.py, line 533, in 
abspath
if not isabs(path):
File /Users/young/anaconda/envs/py34/lib/python3.4/ntpath.py, line 99, in 
isabs
s = splitdrive(s)[1]
File /Users/young/anaconda/envs/py34/lib/python3.4/ntpath.py, line 159, in 
splitdrive
if len(p)  1:
TypeError: object of type 'NoneType' has no len()

--

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