Commit Graph

80 Commits

Author SHA1 Message Date
Nikita Sobolev a384b20c0c
gh-101100: Fix sphinx warnings in `reference/import.rst` (#114646) 2024-01-27 07:30:21 -07:00
Jonathan Berthias 9a2f2f46ca
Fix typos in import system docs (#111396) 2023-10-27 13:20:55 +00:00
Ezio Melotti 41d8ec5a1b
gh-110631: Fix reST indentation in `Doc/reference` (#110708)
Fix wrong indentation in the Doc/reference dir.
2023-10-11 22:50:55 +02:00
Adam Turner 8b03e5ff94
GH-97850: Suppress cross-references to the removed ``module_repr`` method (#104133)
Suppress cross-references to ``module_repr``
2023-05-03 13:57:23 +01:00
Barry Warsaw 326997829d
gh-98040: Remove find_loader, find_module and other deprecated APIs (#98059)
* Remove deprecated classes from pkgutil
* Remove some other PEP 302 obsolescence
* Use find_spec instead of load_module
* Remove more tests of PEP 302 obsolete APIs
* Remove another bunch of tests using obsolete load_modules()
* Remove deleted names from __all__
* Remove obsolete footnote
* imp is removed
* Remove `imp` from generated stdlib names
* What's new and blurb
* Update zipimport documentation for the removed methods
* Fix some Windows tests
* Remove any test (or part of a test) that references `find_module()`.
* Use assertIsNone() / assertIsNotNone() consistently.
* Update Doc/reference/import.rst
* We don't need pkgutil._get_spec() any more either
*  test.test_importlib.fixtures.NullFinder
* ...BadLoaderFinder.find_module
* ...test_api.InvalidatingNullFinder.find_module
* ...test.test_zipimport test of z.find_module
* Suppress cross-references to find_loader and find_module
* Suppress cross-references to Finder
* Suppress cross-references to pkgutil.ImpImporter and pkgutil.ImpLoader

---------

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2023-05-03 04:55:22 -07:00
Barry Warsaw e1f14643dc
gh-98040: Remove just the `imp` module (#98573) 2023-04-28 16:17:58 -07:00
Barry Warsaw 13d4489142
gh-86298: Ensure that __loader__ and __spec__.loader agree in warnings.warn_explicit() (GH-97803)
In `_warnings.c`, in the C equivalent of `warnings.warn_explicit()`, if the module globals are given (and not None), the warning will attempt to get the source line for the issued warning.  To do this, it needs the module's loader.

Previously, it would only look up `__loader__` in the module globals.  In https://github.com/python/cpython/issues/86298 we want to defer to the `__spec__.loader` if available.

The first step on this journey is to check that `loader == __spec__.loader` and issue another warning if it is not.  This commit does that.

Since this is a PoC, only manual testing for now.

```python
# /tmp/foo.py
import warnings

import bar

warnings.warn_explicit(
    'warning!',
    RuntimeWarning,
    'bar.py', 2,
    module='bar knee',
    module_globals=bar.__dict__,
    )
```

```python
# /tmp/bar.py
import sys
import os
import pathlib

# __loader__ = pathlib.Path()
```

Then running this: `./python.exe -Wdefault /tmp/foo.py`

Produces:

```
bar.py:2: RuntimeWarning: warning!
  import os
```

Uncomment the `__loader__ = ` line in `bar.py` and try it again:

```
sys:1: ImportWarning: Module bar; __loader__ != __spec__.loader (<_frozen_importlib_external.SourceFileLoader object at 0x109f7dfa0> != PosixPath('.'))
bar.py:2: RuntimeWarning: warning!
  import os
```

Automerge-Triggered-By: GH:warsaw
2022-10-06 19:32:53 -07:00
Hugo van Kemenade fa2d43e518
Docs: Fix backtick errors found by sphinx-lint (#97998)
Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
2022-10-06 18:01:30 -07:00
Brett Cannon f8edc6ff53
gh-97850: Remove the open issues section from the import reference (#97935)
Remove the open issues section from the import reference

Tracking in https://github.com/python/cpython/issues/97850 instead.
2022-10-06 14:01:06 -07:00
Brett Cannon c206e53bb7
gh-65961: Raise `DeprecationWarning` when `__package__` differs from `__spec__.parent` (#97879)
Also remove `importlib.util.set_package()` which was already slated for removal.

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2022-10-05 15:00:45 -07:00
Barry Warsaw e1182bc377
gh-94619: Remove long deprecated methods module_repr() and load_module() (#94624)
* gh-94619: Remove long deprecated methods module_repr() and load_module()

Closes #94619

* Update Misc/NEWS.d/next/Library/2022-07-06-14-57-33.gh-issue-94619.PRqKVX.rst

Fix typo

Co-authored-by: Brett Cannon <brett@python.org>

Co-authored-by: Brett Cannon <brett@python.org>
2022-08-04 17:24:26 -07:00
Thomas Grainger 6da988a46c
gh-91181: drop support for bytes on sys.path (GH-31934)
Support for bytes broke sometime between Python 3.2 and 3.6 and has been broken ever since. Trying to bring back supports is surprisingly difficult in the face of -b and checking for keys in sys.path_importer_cache. Since the support was broken for so long, trying to overcome the difficulty of bringing back the support has been deemed not worth it.

Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Brett Cannon <brett@python.org>
2022-07-16 18:07:53 -07:00
Ned Batchelder 3440d197a5
Docs: remove redundant "adverb-adjective" hyphens from compound modifiers (GH-94551)
Discussion: https://discuss.python.org/t/slight-grammar-fix-throughout-adverbs-dont-need-hyphen/17021
2022-07-05 11:16:10 +02:00
slateny b87f7f2c21
bpo-21761: Clarify __file__/__cached__ in import reference (GH-31565)
Automerge-Triggered-By: GH:brettcannon
2022-04-26 12:12:02 -07:00
slateny d5a69571f5
gh-89885: Improve import example in language reference (#91523)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-04-17 14:20:13 -07:00
David Gilbertson 28f84c72b6
Removed confusing reference to sys (GH-31638) 2022-03-08 07:43:27 -08:00
Christian Clauss 241bda785a
[doc] Fix typos found using codespell (GH-28744)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-10-05 23:48:44 +02:00
Jack DeVries 7cba23164c
bpo-39452: Rewrite and expand __main__.rst (#26883)
Broadened scope of the document to explicitly discuss and differentiate between ``__main__.py`` in packages versus the ``__name__ == '__main__'`` expression (and the idioms that surround it), as well as ``import __main__``.

Co-authored-by: Géry Ogam <gery.ogam@gmail.com>
Co-authored-by: Éric Araujo <merwok@netwok.org>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-08-24 19:01:41 +02:00
Furkan Onder 878d7e4ee4
bpo-21760: fix __file__ description (GH-19097) 2021-06-09 14:10:20 -07:00
Brett Cannon f97dc80068
bpo-43672: raise ImportWarning when calling find_loader() (GH-25119) 2021-04-02 12:35:32 -07:00
Brett Cannon a7ff6df60c
bpo-42134: Raise ImportWarning when calling find_module() in the import system (GH-25044) 2021-03-30 08:43:03 -07:00
Brett Cannon 1899087b21
bpo-42136: Deprecate module_repr() as found in importlib (GH-25022) 2021-03-26 11:55:07 -07:00
Géry Ogam 27f1bd8787
bpo-35181: Correct importlib documentation for some module attributes (GH-15190)
@ericsnowcurrently This PR will change the following:

In the library documentation importlib.rst:

- `module.__package__` can be `module.__name__` for packages;
- `spec.parent` can be `spec.__name__` for packages;
- `spec.loader` is not `None` for namespaces packages.

In the language documentation import.rst:

- `spec.loader` is not `None` for namespace packages.

Automerge-Triggered-By: GH:warsaw
2020-10-21 14:17:35 -07:00
Zackery Spytz cb115e36e1
Doc: Fix a typo/error in the docs for cached bytecode (GH-22445) 2020-10-21 17:36:03 +09:00
Bonifacio de Oliveira d47d0c8e9f
Improve grammar in the import system reference documentation (GH-18209)
Replaced the period with a comma.

Automerge-Triggered-By: @Mariatta
2020-01-29 18:23:50 -08:00
Oleg Höfling cbd0408b54 links in importlib.metadata.rst replaced with sphinx references (GH-17730)
The importlib.metadata documentation uses hardcoded links to internal
pages. This results in minor rendering issues. This change replaces
the hardcoded links with suitable Sphinx roles.

Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>
2019-12-29 12:26:35 -05:00
Shu 2d56af7a94 Fix minor typos. (GH-17095) 2019-11-12 19:12:11 -08:00
Shu fc6b1bf869 Clarify amount of dots between package and subpackage (GH-17092) 2019-11-08 12:26:35 -08:00
Géry Ogam ee88af3f4f Namespace packages _bootstrap.ModuleSpec.loader attributes are no longer None (#10376)
Namespace packages _bootstrap.ModuleSpec.loader attributes are no longer `None` _after_ calling the importlib._bootstrap._init_module_attrs function.

See:
* https://stackoverflow.com/questions/52869541/namespace-package-spec-loader-and-loader-attributes-not-set-to-none
* https://bugs.python.org/issue35181
2019-05-01 13:08:17 -07:00
Joannah Nanjekye 70bf713617 bpo-30840: Document relative imports (#12831)
* document relative imports

* 📜🤖 Added by blurb_it.

* fix indentation error

* remove indentation

* Document relative imports

* Document relative imports

* remove from ...package

* Document relative imports

* remove trailing space

* Document relative imports

* Document relative imports
2019-04-25 01:14:44 +10:00
Serhiy Storchaka 2b57c43f21
bpo-35506: Remove redundant and incorrect links from keywords. (GH-11174) 2018-12-19 08:09:46 +02:00
Andrés Delfino ea6a28c9f7 Mark -c and -O as command line options in reStructuredText. (GH-10103) 2018-11-07 19:06:45 +02:00
Serhiy Storchaka ddb961d2ab
bpo-35054: Add more index entries for symbols. (GH-10064) 2018-10-26 09:00:49 +03:00
Brett Cannon 441d945eb3
Clarify that __path__ can't be just any value (GH-6554) 2018-04-20 16:32:46 -07:00
Benjamin Peterson 42aa93b8ff
closes bpo-31650: PEP 552 (Deterministic pycs) implementation (#4575)
Python now supports checking bytecode cache up-to-dateness with a hash of the
source contents rather than volatile source metadata. See the PEP for details.

While a fairly straightforward idea, quite a lot of code had to be modified due
to the pervasiveness of pyc implementation details in the codebase. Changes in
this commit include:

- The core changes to importlib to understand how to read, validate, and
  regenerate hash-based pycs.

- Support for generating hash-based pycs in py_compile and compileall.

- Modifications to our siphash implementation to support passing a custom
  key. We then expose it to importlib through _imp.

- Updates to all places in the interpreter, standard library, and tests that
  manually generate or parse pyc files to grok the new format.

- Support in the interpreter command line code for long options like
  --check-hash-based-pycs.

- Tests and documentation for all of the above.
2017-12-09 10:26:52 -08:00
Barry Warsaw 93952f8815
Fix a grammatical problem and reword for clarity. (#4257)
bpo-31936
2017-11-03 13:45:46 -07:00
Barry Warsaw 191e313820 bpo-31799: Make module.__spec__ more discoverable (#4010)
bpo-31799: Make module.__spec__ more discoverable
2017-10-17 15:52:38 -04:00
Benjamin Peterson 60dbed1850 link to legacy doc on the non-legacy website (#3362) 2017-09-05 16:24:39 -07:00
kms70847 9c972b5780 Improve grammar in The Import System documentation (GH-1862)
Replace `an ModuleNotFoundError` with `a ModuleNotFoundError`.
Replace `an path` with `a path`.
2017-05-30 09:12:33 -07:00
Dominik Miedziński af34e0a07b Fix ModuleNotFoundError typo in import reference (#1606) 2017-05-16 19:40:17 +03:00
Mariatta 1f5639c77f bpo-26184: import.rst: Improve versionchanged note (GH-325) 2017-02-26 13:23:38 -08:00
Mariatta 6b4a5f45e2 bpo-26184: import.rst: Improve versionchanged note (GH-277)
Mention that an ImportError is raised when exec_module() is defined, but
create_module() is not.
2017-02-26 07:36:57 -08:00
Marco Buttu 46ce7599af bpo-29648: import.rst: Add reference to create_module() (GH-290)
Add a reference to create_module(), in the first versionadded of section Loaders.
2017-02-26 07:14:45 -08:00
Eric Snow 46f97b85a8 Issue #15767: Use ModuleNotFoundError. 2016-09-07 16:56:15 -07:00
Brett Cannon 3f63483a30 Merge for issue #27712 2016-08-12 10:57:17 -07:00
Brett Cannon 6336fb2734 Issue #27712: Fix some typos in the import docs.
Thanks to Xiang Zhang for the patch.
2016-08-12 10:56:48 -07:00
Brett Cannon 849113af6b Issue #25791: Warn when __package__ != __spec__.parent.
In a previous change, __spec__.parent was prioritized over
__package__. That is a backwards-compatibility break, but we do
eventually want __spec__ to be the ground truth for module details. So
this change reverts the change in semantics and instead raises an
ImportWarning when __package__ != __spec__.parent to give people time
to adjust to using spec objects.
2016-01-22 15:25:50 -08:00
Brett Cannon 63b8505281 Issue #25791: Raise an ImportWarning when __spec__ or __package__ are
not defined for a relative import.

This is the start of work to try and clean up import semantics to rely
more on a module's spec than on the myriad attributes that get set on
a module. Thanks to Rose Ames for the patch.
2016-01-15 13:33:03 -08:00
Brett Cannon f4f25fe576 Issue #25500: Fix the language reference to not claim that import
statements search for __import__ in the global scope.

Thanks to Sergei Lebedev for finding the documentation bug.
2015-12-04 14:51:26 -08:00
Berker Peksag a1bddadddd Issue #24713: Use importlib.reload() in import reference document.
imp.reload() was deprecated in Python 3.4 and changed to call
importlib.reload().

Patch by Petr Viktorin.
2015-07-25 13:03:08 +03:00