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.
...variable, whereas pkgutil doesn't. In addition, the current approach causes problems for system vendors. Vendor packages typically must not provide overlapping files, and an attempt to install a vendor package that has a file already on disk will fail or cause unpredictable behavior. As vendors might chose to package distributions such that they will end up all in a single directory for the namespace package, all portions would contribute conflicting __init__.py files. Specification Rather tha...
...variable (it should not be used as part of a larger expression). The argument to TypeVar() must be a string equal to the variable name to which it is assigned. Type variables must not be redefined. TypeVar supports constraining parametric types to a fixed set of possible types (note: those types cannot be parameterized by type variables). For example, we can define a type variable that ranges over just str and bytes. By default, a type variable ranges over all possible types. Example of constr...
...variable defined by __slots__; the __slots__ declaration creates a class attribute for each variable containing a descriptor, and setting a class attribute to a default value would overwrite this descriptor. There's no check that prevents you to override an instance variable already defined by a base class using a __slots__ declaration. If you do that, the instance variable defined by the base class is inaccessible (except by retrieving its descriptor directly from the base class; thi...
...declaration as a declaration of "iso-8859-1". This will cause arbitrary byte strings to correctly round-trip between step 2 and step 5 of the processing, and provide compatibility with Python 2.2 for Unicode literals that contain non-ASCII bytes. A warning will be issued if non-ASCII bytes are found in the input, once per improperly encoded input file. Remove the warning, and change the default encoding to "ascii". The builtin compile() API will be enhanced to accept Unicode as input. 8-bit ...
...declaration. A solution to this problem is to move the transformation of the method closer to the method's own declaration. The intent of the new syntax is to replace def foo(cls): pass foo = synchronized(lock)(foo) foo = classmethod(foo) with an alternative that places the decoration in the function's declaration: @classmethod @synchronized(lock) def foo(cls): pass Modifying classes in this fashion is also possible, though the benefits are not as immediately apparent. Almost certa...
...variable. Although this is being proposed as a general mechanism, the author currently only foresees this as being useful for module objects. Implementation The basic idea is simple: modify the tp_descr_get and tp_descr_set functions exposed by PyModule_Type to inspect the attribute interacted with, and if it supports the descriptor protocol, call the relevant exposed function. Our implementation faces two challenges: Since this code will be run every time an attribute is looked up on a metho...
...variables can be found by inspection of x's class, written as x.__class__. Classes have a __dict__ attribute, which yields a dictionary containing methods and class variables defined by the class itself, and a __bases__ attribute, which is a tuple of base classes that must be inspected recursively. Some assumptions here are: attributes defined in the instance dict override attributes defined by the object's class; attributes defined in a derived class override attributes defined in a base clas...
Python Software Foundation Board Meeting Minutes 2006-02-25 The Python Software Foundation Minutes of a Special Meeting of the Board of Directors February 25, 2006 A special meeting of the Python Software Foundation ("PSF") Board of Directors was held at PyCon in Dallas at 12:15 CST (18:15 UTC), 25 February 2006. Stephan Deibel presided at the meeting. 1 Attendance The following members of the Board of Directors were present at the meeting: Stephan Deibel, Mart...
...variable doubles the memory used by a defaultdict instance compared to using a regular dictionary! There's a way to avoid this: class defaultdict2(dict): __slots__ = ['default'] def __init__(self, default=None): ...(like before)... The __slots__ declaration takes a list of instance variables, and reserves space in the instance for exactly these in the instance. When __slots__ is used, other instance variables cannot be assigned to: >>> a...
...variable doubles the memory used by a defaultdict instance compared to using a regular dictionary! There's a way to avoid this: class defaultdict2(dict): __slots__ = ['default'] def __init__(self, default=None): ...(like before)... The __slots__ declaration takes a list of instance variables, and reserves space in the instance for exactly these in the instance. When __slots__ is used, other instance variables cannot be assigned to: >>> a = defaultdict2(defa...
...variables An attribute access handler that attempts to call setattr or getattr on the object itself can cause an infinite loop (as with __getattr__) Once again, the solution is to use a special (typically private) variable such as __XXX. Note The descriptor mechanism described in PEP 252 is powerful enough to support this more directly. A 'getset' constructor may be added to the language making this possible: class C: def get_x(self): return self.__x def set_x(self, v): ...
...variable assignments. Based on the similar guidelines already present for try statements, this PEP proposes the following additions for given statements to the "Programming Conventions" section of PEP 8: for code that could reasonably be factored out into a separate function, but is not currently reused anywhere, consider using a given clause. This clearly indicates which variables are being used only to define subcomponents of another statement rather than to hold algorithm or application stat...
...variables. As a dynamically typed language, Python can be less restrictive here and allow capture patterns inside OR patterns. However, each subpattern must bind the same set of variables so as not to leave potentially undefined names. With two alternatives P | Q, this means that if P binds the variables u and v, Q must bind exactly the same variables u and v. There was some discussion on whether to use the bar symbol | or the or keyword to separate alternatives. The OR pattern does not full...
...variables and their values in 'ctx': print(ctx.items()) # Print the value of 'some_variable' in context 'ctx': print(ctx[some_variable]) Note that all Mapping methods, including Context.__getitem__ and Context.get, ignore default values for context variables (i.e. ContextVar.default). This means that for a variable var that was created with a default value and was not set in the context: context[var] raises a KeyError, var in context returns False, the variable isn't included in context.item...
...variable s: s = "X" * 100 # "X" is assigned When the X is replaced by the Hebrew letter א, the line becomes: s = "א" * 100 # "א" is assigned This command still assigns a 100-character string to s, but when displayed as general text following the Bidirectional Algorithm (e.g. in a browser), it appears as s = "א" followed by a comment. Other surprising examples include: In the statement ערך = 23, the variable ערך is set to the integer 23. In the statement قيمة = ערך, the variable قيمة i...
...variables listed below. VEREXPR is a PEP 440 version identifier, or one of the Version number marker variables listed below. Comparisons between version numbers are done using PEP 440 semantics. Strings os_name: os.name sys_platform: sys.platform platform_release: platform.release() implementation_name: sys.implementation.name platform_machine: platform.machine() platform_python_implementation: platform.python_implementation() If a particular string value is not available (such as sys.impleme...
...Variable/Attribute Access, proposes a different mechanism for optimizing access to global variables as well as attributes of objects. The mechanism uses two new opcodes TRACK_OBJECT and UNTRACK_OBJECT to create a slot in the local variables array that aliases the global or object attribute. If the object being aliases is rebound, the rebind operation is responsible for updating the aliases. The objecting tracking approach applies to a wider range of objects than just module. It may also have ...
...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.StrictVersion class: two or three dot-separated numeric components, with an optional "pre-release" tag on the end consisting of the letter 'a' or 'b' followed by a number. Example version numbers are "1.0"...
...variable has a specific and concrete value. For example, if we define some variable foo to have type Literal[3], we are declaring that foo must be exactly equal to 3 and no other value. Given some value v that is a member of type T, the type Literal[v] shall be treated as a subtype of T. For example, Literal[3] is a subtype of int. All methods from the parent type will be directly inherited by the literal type. So, if we have some variable foo of type Literal[3] it’s safe to do things like foo +...