@@ -249,7 +249,7 @@ ABC hierarchy::
249
249
An abstract method for finding a :term: `spec <module spec> ` for
250
250
the specified module. If this is a top-level import, *path * will
251
251
be ``None ``. Otherwise, this is a search for a subpackage or
252
- module and *path * will be the value of :attr: `__path__ ` from the
252
+ module and *path * will be the value of :attr: `~module. __path__ ` from the
253
253
parent package. If a spec cannot be found, ``None `` is returned.
254
254
When passed in, ``target `` is a module object that the finder may
255
255
use to make a more educated guess about what spec to return.
@@ -355,34 +355,12 @@ ABC hierarchy::
355
355
(note that some of these attributes can change when a module is
356
356
reloaded):
357
357
358
- - :attr: `__name__ `
359
- The module's fully qualified name.
360
- It is ``'__main__' `` for an executed module.
361
-
362
- - :attr: `__file__ `
363
- The location the :term: `loader ` used to load the module.
364
- For example, for modules loaded from a .py file this is the filename.
365
- It is not set on all modules (e.g. built-in modules).
366
-
367
- - :attr: `__cached__ `
368
- The filename of a compiled version of the module's code.
369
- It is not set on all modules (e.g. built-in modules).
370
-
371
- - :attr: `__path__ `
372
- The list of locations where the package's submodules will be found.
373
- Most of the time this is a single directory.
374
- The import system passes this attribute to ``__import__() `` and to finders
375
- in the same way as :data: `sys.path ` but just for the package.
376
- It is not set on non-package modules so it can be used
377
- as an indicator that the module is a package.
378
-
379
- - :attr: `__package__ `
380
- The fully qualified name of the package the module is in (or the
381
- empty string for a top-level module).
382
- If the module is a package then this is the same as :attr: `__name__ `.
383
-
384
- - :attr: `__loader__ `
385
- The :term: `loader ` used to load the module.
358
+ - :attr: `module.__name__ `
359
+ - :attr: `module.__file__ `
360
+ - :attr: `module.__cached__ ` *(deprecated) *
361
+ - :attr: `module.__path__ `
362
+ - :attr: `module.__package__ ` *(deprecated) *
363
+ - :attr: `module.__loader__ ` *(deprecated) *
386
364
387
365
When :meth: `exec_module ` is available then backwards-compatible
388
366
functionality is provided.
@@ -418,7 +396,8 @@ ABC hierarchy::
418
396
can implement this abstract method to give direct access
419
397
to the data stored. :exc: `OSError ` is to be raised if the *path * cannot
420
398
be found. The *path * is expected to be constructed using a module's
421
- :attr: `__file__ ` attribute or an item from a package's :attr: `__path__ `.
399
+ :attr: `~module.__file__ ` attribute or an item from a package's
400
+ :attr: `~module.__path__ `.
422
401
423
402
.. versionchanged :: 3.4
424
403
Raises :exc: `OSError ` instead of :exc: `NotImplementedError `.
@@ -505,9 +484,9 @@ ABC hierarchy::
505
484
506
485
.. abstractmethod :: get_filename(fullname)
507
486
508
- An abstract method that is to return the value of :attr: ` __file__ ` for
509
- the specified module. If no path is available, :exc: ` ImportError ` is
510
- raised.
487
+ An abstract method that is to return the value of
488
+ :attr: ` ~module.__file__ ` for the specified module. If no path is
489
+ available, :exc: ` ImportError ` is raised.
511
490
512
491
If source code is available, then the method should return the path to
513
492
the source file, regardless of whether a bytecode was used to load the
@@ -1166,43 +1145,45 @@ find and load modules.
1166
1145
.. class :: ModuleSpec(name, loader, *, origin=None, loader_state=None, is_package=None)
1167
1146
1168
1147
A specification for a module's import-system-related state. This is
1169
- typically exposed as the module's :attr: `__spec__ ` attribute. Many
1148
+ typically exposed as the module's :attr: `~module. __spec__ ` attribute. Many
1170
1149
of these attributes are also available directly on a module: for example,
1171
1150
``module.__spec__.origin == module.__file__ ``. Note, however, that
1172
1151
while the *values * are usually equivalent, they can differ since there is
1173
- no synchronization between the two objects. For example, it is possible to update
1174
- the module's :attr: `__file__ ` at runtime and this will not be automatically
1175
- reflected in the module's :attr: `__spec__.origin `, and vice versa.
1152
+ no synchronization between the two objects. For example, it is possible to
1153
+ update the module's :attr: `~module.__file__ ` at runtime and this will not be
1154
+ automatically reflected in the module's
1155
+ :attr: `__spec__.origin <ModuleSpec.origin> `, and vice versa.
1176
1156
1177
1157
.. versionadded :: 3.4
1178
1158
1179
1159
.. attribute :: name
1180
1160
1181
- The module's fully qualified name
1182
- (see :attr: `__name__ ` attributes on modules).
1161
+ The module's fully qualified name (see :attr: `module.__name__ `).
1183
1162
The :term: `finder ` should always set this attribute to a non-empty string.
1184
1163
1185
1164
.. attribute :: loader
1186
1165
1187
- The :term: `loader ` used to load the module
1188
- (see :attr: `__loader__ ` attributes on modules).
1166
+ The :term: `loader ` used to load the module (see :attr: `module.__loader__ `).
1189
1167
The :term: `finder ` should always set this attribute.
1190
1168
1191
1169
.. attribute :: origin
1192
1170
1193
1171
The location the :term: `loader ` should use to load the module
1194
- (see :attr: `__file__ ` attributes on modules ).
1195
- For example, for modules loaded from a .py file this is the filename.
1172
+ (see :attr: `module. __file__ `).
1173
+ For example, for modules loaded from a `` .py `` file this is the filename.
1196
1174
The :term: `finder ` should always set this attribute to a meaningful value
1197
1175
for the :term: `loader ` to use. In the uncommon case that there is not one
1198
1176
(like for namespace packages), it should be set to ``None ``.
1199
1177
1200
1178
.. attribute :: submodule_search_locations
1201
1179
1202
- The list of locations where the package's submodules will be found
1203
- (see :attr: `__path__ ` attributes on modules).
1204
- Most of the time this is a single directory.
1205
- The :term: `finder ` should set this attribute to a list, even an empty one, to indicate
1180
+ A (possibly empty) :term: `sequence ` of strings enumerating the locations
1181
+ in which a package's submodules will be found
1182
+ (see :attr: `module.__path__ `). Most of the time there will only be a
1183
+ single directory in this list.
1184
+
1185
+ The :term: `finder ` should set this attribute to a sequence, even an empty
1186
+ one, to indicate
1206
1187
to the import system that the module is a package. It should be set to ``None `` for
1207
1188
non-package modules. It is set automatically later to a special object for
1208
1189
namespace packages.
@@ -1216,22 +1197,22 @@ find and load modules.
1216
1197
.. attribute :: cached
1217
1198
1218
1199
The filename of a compiled version of the module's code
1219
- (see :attr: `__cached__ ` attributes on modules ).
1200
+ (see :attr: `module. __cached__ `).
1220
1201
The :term: `finder ` should always set this attribute but it may be ``None ``
1221
1202
for modules that do not need compiled code stored.
1222
1203
1223
1204
.. attribute :: parent
1224
1205
1225
1206
(Read-only) The fully qualified name of the package the module is in (or the
1226
1207
empty string for a top-level module).
1227
- See :attr: `__package__ ` attributes on modules .
1208
+ See :attr: `module. __package__ `.
1228
1209
If the module is a package then this is the same as :attr: `name `.
1229
1210
1230
1211
.. attribute :: has_location
1231
1212
1232
1213
``True `` if the spec's :attr: `origin ` refers to a loadable location,
1233
- ``False `` otherwise. This value impacts how :attr: `origin ` is interpreted
1234
- and how the module's :attr: `__file__ ` is populated.
1214
+ ``False `` otherwise. This value impacts how :attr: `! origin ` is interpreted
1215
+ and how the module's :attr: `~module. __file__ ` is populated.
1235
1216
1236
1217
1237
1218
.. class :: AppleFrameworkLoader(name, path)
@@ -1416,8 +1397,8 @@ an :term:`importer`.
1416
1397
1417
1398
.. versionchanged :: 3.7
1418
1399
Raises :exc: `ModuleNotFoundError ` instead of :exc: `AttributeError ` if
1419
- **package ** is in fact not a package (i.e. lacks a :attr: ` __path__ `
1420
- attribute).
1400
+ **package ** is in fact not a package (i.e. lacks a
1401
+ :attr: ` ~module.__path__ ` attribute).
1421
1402
1422
1403
.. function :: module_from_spec(spec)
1423
1404
0 commit comments