Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccurate docs on import behaviour #77521

Closed
samb mannequin opened this issue Apr 23, 2018 · 4 comments
Closed

Inaccurate docs on import behaviour #77521

samb mannequin opened this issue Apr 23, 2018 · 4 comments
Labels
3.8 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@samb
Copy link
Mannequin

samb mannequin commented Apr 23, 2018

BPO 33340
Nosy @brettcannon, @ericvsmith, @tirkarthi

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2018-04-23.09:51:36.081>
labels = ['type-feature', '3.8', 'docs']
title = 'Inaccurate docs on `import` behaviour'
updated_at = <Date 2019-05-06.14:12:08.875>
user = 'https://bugs.python.org/samb'

bugs.python.org fields:

activity = <Date 2019-05-06.14:12:08.875>
actor = 'cheryl.sabella'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2018-04-23.09:51:36.081>
creator = 'sam_b'
dependencies = []
files = []
hgrepos = []
issue_num = 33340
keywords = []
message_count = 4.0
messages = ['315653', '315655', '315657', '315658']
nosy_count = 5.0
nosy_names = ['brett.cannon', 'eric.smith', 'docs@python', 'sam_b', 'xtreak']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue33340'
versions = ['Python 3.8']

@samb
Copy link
Mannequin Author

samb mannequin commented Apr 23, 2018

The docs https://docs.python.org/3/tutorial/modules.html#the-module-search-path describe:

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:

  • The directory containing the input script (or the current directory when no file is specified).
  • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
  • The installation-dependent default.

However, it seems like "the directory containing the input script" is checked *before* the standard library:

➜  tmp more logging.py
def foo():
    print('bar')
➜  tmp python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.foo()
bar
>>> logging.WARNING
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'WARNING'
>>> 

Am I misunderstanding the docs?

@samb samb mannequin added the type-bug An unexpected behavior, bug, or error label Apr 23, 2018
@samb samb mannequin assigned docspython Apr 23, 2018
@samb samb mannequin added the docs Documentation in the Doc dir label Apr 23, 2018
@ericvsmith
Copy link
Member

"built-in modules" has the specific meaning of modules that are compiled in to the python executable. It doesn't mean modules in the standard library.

See https://docs.python.org/3.6/library/sys.html#sys.builtin_module_names

Python 3.6.4 (default, Jan  7 2018, 15:53:53)
[GCC 6.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.builtin_module_names
('_ast', '_codecs', '_collections', '_functools', '_imp', '_io', '_locale', '_operator', '_signal', '_sre', '_stat', '_string', '_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref', 'atexit', 'builtins', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal', 'posix', 'pwd', 'sys', 'time', 'xxsubtype', 'zipimport')

@samb
Copy link
Mannequin Author

samb mannequin commented Apr 23, 2018

Thanks, I thought it might be something like that. Would it be worth clarifying the distinction in the docs? It was certainly surprising to me that import time and import logging behave differently.

@ericvsmith
Copy link
Member

If you have a suggested improvement, please create a pull request. Thanks!

@csabella csabella added 3.8 only security fixes type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels May 6, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 8, 2022
…ythonGH-92438)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 859250c)

Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
JelleZijlstra added a commit that referenced this issue May 8, 2022
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 8, 2022
…ythonGH-92438)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 859250c)

Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 8, 2022
…ythonGH-92438)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 859250c)

Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
miss-islington added a commit that referenced this issue May 8, 2022
)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 859250c)

Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
miss-islington added a commit that referenced this issue May 8, 2022
)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 859250c)

Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
miss-islington added a commit that referenced this issue May 8, 2022
)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 859250c)

Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
@slateny slateny closed this as completed May 12, 2022
hello-adam pushed a commit to hello-adam/cpython that referenced this issue Jun 2, 2022
…ythonGH-92438)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 859250c)

Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants