[issue34444] Module's __file__ should be absolute always ("." in sys.path)

2020-01-02 Thread Brett Cannon


Brett Cannon  added the comment:

RE: "This could be done when inserting something into `sys.path` maybe then 
only?" That would require a custom object instead of a standard list for 
sys.path which could detect insertion and then do the automatic absolute path 
resolution which as you pointed out will inevitably break things for someone 
somewhere.

--

___
Python tracker 

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



[issue34444] Module's __file__ should be absolute always ("." in sys.path)

2019-12-24 Thread daniel hahler


daniel hahler  added the comment:

> And changing this to have to check every time import runs if an entry in 
> sys.path is absolute would be costly (that's not a insignificant number of 
> stat calls which we always try to avoid during import when possible).

This could be done when inserting something into `sys.path` maybe then only?
But might only make sense when there is some special handling in that case 
already though - and would change existing behavior of course.
(Therefore I am OK with rejecting this, but wanted to mention it anyway)

> Your best option is to insert an absolute path to begin with.

That's a good enough option to have anyway, of course.

--

___
Python tracker 

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



[issue34444] Module's __file__ should be absolute always ("." in sys.path)

2019-12-24 Thread Brett Cannon


Brett Cannon  added the comment:

So if you were to insert '.' via PYTHONPATH it would be made absolute as the 
site module makes all entries in sys.path absolute during startup.

And changing this to have to check every time import runs if an entry in 
sys.path is absolute would be costly (that's not a insignificant number of stat 
calls which we always try to avoid during import when possible). Your best 
option is to insert an absolute path to begin with. Also realize that 
manipulating sys.path is an advanced thing to do and so I don't think asking 
people to be "consenting adults" and be careful about adding relative paths on 
sys.path is an unreasonable thing to ask.

So while I appreciate the report, Daniel, and the motivation, I'm closing this 
as "won't fix" as the overhead of implementing this is too high.

--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed
type:  -> enhancement

___
Python tracker 

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



[issue34444] Module's __file__ should be absolute always ("." in sys.path)

2019-12-21 Thread Batuhan


Batuhan  added the comment:

I am not sure about computing absolute path every time when `__file__` called. 
I guess it is a static thing, that get setted on the import time and never 
changes. What you are proposing is to compute it dynamically which IMHO isn't 
the best way.

--
nosy: +BTaskaya, brett.cannon, eric.snow, ncoghlan

___
Python tracker 

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



[issue34444] Module's __file__ should be absolute always ("." in sys.path)

2018-08-20 Thread daniel hahler


New submission from daniel hahler :

With "." in sys.path the "__file__" attribute will be a relative path, and 
therefore cannot be used after "chdir".

This likely affects relative paths in general, but have not tested it.

```
import os
import sys

sys.path.insert(0, '.')

# Importing it before chdir already causes failure.
import imported

os.chdir('/')
print(imported.__file__)  # ./imported.py
assert imported.__file__ == os.path.abspath(imported.__file__)
```

It works for "" in sys.path (https://bugs.python.org/issue18416).

--
components: Interpreter Core
messages: 323800
nosy: blueyed
priority: normal
severity: normal
status: open
title: Module's __file__ should be absolute always ("." in sys.path)
versions: Python 3.7

___
Python tracker 

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