Notice: While JavaScript is not essential for this website, your interaction with the content will be limited. Please turn JavaScript on for the full experience.
...Modules PEP:4 Title:Deprecation of Standard Modules Author:Brett Cannon <brett at python.org>, Martin von Löwis <martin at v.loewis.de> Status:Active Type:Process Created:01-Oct-2000 Post-History: Contents Introduction Procedure for declaring a module deprecated For modules existing in both Python 2.7 and Python 3.5 Procedure for declaring a module undeprecated Obsolete modules Deprecated modules Deprecation of modules removed in Python 3.0 Undeprecated modules Co...
...declaration followed by the docstring. Module and Class Declarations When a C file implements a module or class, this should be declared to Clinic. The syntax is simple: module module_name or class module_name.class_name (Note that these are not actually special syntax; they are implemented as Directives.) The module name or class name should always be the full dotted path from the top-level module. Nested modules and classes are supported. Function Declaration The full form of the fun...
...module global scopes, the answer to both of those questions is unequivocally "Yes", because it's a language level guarantee that mutating the globals() dict will immediately impact the runtime module scope, and global NAME declarations inside a function can have the same effect (as can importing the currently executing module and modifying its attributes). For class scopes, the answer to both questions is also "Yes" in practice, although less unequivocally so, since the semantics of locals() are...
...module---in the form of a final decorator and a Final type annotation---to serve three related purposes: Declaring that a method should not be overridden Declaring that a class should not be subclassed Declaring that a variable or attribute should not be reassigned Motivation The final decorator The current typing module lacks a way to restrict the use of inheritance or overriding at a typechecker level. This is a common feature in other object-oriented languages (such as Java), and is usef...
...declaration. Function definition: def name ... Argument declaration: def f(...name...), lambda ...name... Class definition: class name ... Assignment statement: name = ... Import statement: import name, import module as name, from module import name Implicit assignment: names are bound by for statements and except clauses There are several cases where Python statements are illegal when used in conjunction with nested scopes that contain free variables. If a variable is referenced in an...
...modules. New module 'fileinput' to iterate over the lines of a list of files. New module 'locale' for localized number formatting and string case sensitivity. New module 'xmllib' to parse XML files. Some more support for Tk extensions (PIL, TIX, BLT, TOGL). Fixed address list parsing in module 'rfc822'. More deployment (and only one fix) for the 're' module. New Python mode for Emacs. OS/2 support. From 1.5b1 to 1.5b2 Thanks to all who contributed doc strings for library modules! The portabi...
...module or package required by this package. The format of a requirement string is identical to that of a module or package name usable with the 'import' statement, optionally followed by a version declaration within parentheses. A version declaration is a series of conditional operators and version numbers, separated by commas. Conditional operators must be one of "<", ">", "<=", ">=", "==", and "!=". Version numbers must be in the format accepted by the distutils.version.StrictVer...
...modules (including __init__.py) will continue to stop at the first module encountered. In summary, the process import a package foo works like this: sys.path is searched for directories foo or foo.pyp, or a file foo.<ext>. If a file is found and no directory, it is treated as a module, and imported. If a directory foo is found, a check is made whether it contains __init__.py. If so, the location of the __init__.py is remembered. Otherwise, the directory is skipped. Once an __init__.py is ...
...modules and classes never seem to be documented quite right. The documentation provided may be enough to convince a programmer to use a particular module or class over another, but the programmer almost always has to read the source code when the real debugging starts. Contracts extend the excellent example provided by the doctest module [4]. Documentation is readable by programmers, yet has executable tests embedded in it. Testing code with contracts is easier too. Comprehensive contracts are...
...module. Don't make your users instantiate a singleton class, don't make your users have to dereference through a singleton object stored in a module, just have module-level functions and module-level data. Unfortunately these two best practices are in opposition. The problem is that properties aren't supported on modules. Modules are instances of a single generic module type, and it's not feasible to modify or subclass this type to add a property to one's module. This means that programmers fa...
...modules are already provided pre-compiled for that version. If additional modules are needed, or additional Python versions, users can typically compile them themselves on the system, resulting in modules that use the right ABI. On Windows, multiple simultaneous installations of different Python versions are common, and extension modules are compiled by their authors, not by end users. To reduce the risk of ABI incompatibilities, Python currently introduces a new DLL name pythonXY.dll for each f...
...declaration rules create confusion when type aliases involve forward references, invalid types, or violate other restrictions enforced on type alias declaration. Because the distinction between an unannotated value and a type alias is implicit, ambiguous or incorrect type alias declarations implicitly default to a valid value assignment. This creates expressions that are impossible to express as type aliases and punts error diagnosis of malformed type aliases downstream. The following examples e...
...module module:name module[requires_extra] module:name[requires_extra] Note The jsonschema file currently restricts qualified names using the Python 2 ASCII identifier rules. This may need to be reconsidered given the more relaxed identifier rules in Python 3. The meaning of the subfields is as follows: module: the module providing the export name: if applicable, the qualified name of the export within the module requires_extra: indicates the export will only work correctly if the additional ...
...declarations may be placed into .c files. Duplicate declarations are allowed as long as the function types are identical. It is encouraged to declare custom converter types a second time right above the converter function definition. The preprocessor will then catch any mismatch between the declarations. In order to keep the converter complexity manageable, PY_SSIZE_T_CLEAN will be deprecated and Py_ssize_t will be assumed for all length arguments. TBD: Make a list of fantasy types like rw_buffe...
...declaration contracts the scope of an existing name, so inadvertently omitting the declaration could yield farther-reaching (i.e. more dangerous) effects than expected. In Python with this proposal, the extra effort of adding the declaration is aligned with the increased risk of non-local effects (i.e. the path of least resistance is the safer path). Many spellings have been suggested for such a declaration: scoped x [1] global x in f [3] (explicitly specify which scope) free x [5] outer x [6]...
...modules and packages, the qualified name is available as the __name__ attribute, while for functions and classes it is available as the __qualname__ attribute. A "fully qualified name" uniquely locates an object in the Python module namespace. For imported modules and packages, it is the same as the qualified name. For other Python objects, the fully qualified name consists of the qualified name of the containing module or package, a colon (:) and the qualified name of the object relative to the...
...Modules as implementations of protocols A module object is accepted where a protocol is expected if the public interface of the given module is compatible with the expected protocol. For example: # file default_config.py timeout = 100 one_flag = True other_flag = False # file main.py import default_config from typing import Protocol class Options(Protocol): timeout: int one_flag: bool other_flag: bool def setup(options: Options) -> None: ... setup(default_config) # OK T...
...modules and user modules in individual files which can easily be rearranged or distributed outside the system. One consequence is that there is more than one option for attaching a Graphical User Interface (GUI) to a Python program, since the GUI is not built into the system. C++ Almost everything said for Java also applies for C++, just more so: where Python code is typically 3-5 times shorter than equivalent Java code, it is often 5-10 times shorter than equivalent C++ code! Anecd...
...declaration of C structs; COM objects; Automatic translation of Python classes into IDL or database schemas, such as used in an ORM; and so on. In such cases, it would be useful for a Python programmer to specify such ordering directly using the declaration order of class members. Currently, such orderings must be specified explicitly, using some other mechanism (see the ctypes module for an example.) Unfortunately, the current method for declaring a metaclass does not allow for this, since the ...
...module into a package, turn roletypes and format into submodules, and move the attributes to the submodules. Create roletypes and format classes, and move the attributes to the classes. The former is a fair chunk of refactoring work, and produces two tiny modules without much content. The latter keeps the attributes local to the module, but creates classes when there is no intention of ever creating instances of those classes. In situations like this, it would be nice to simply be able to decl...