-
Notifications
You must be signed in to change notification settings - Fork 304
WhatsNew–Python3.1
Lamparter edited this page Nov 18, 2024
·
1 revision
Important
This file is used by maintainers to track implementation of core functionality from Python 3 into IronPython.
https://docs.python.org/3/whatsnew/3.1.html
- Directories and zip archives containing a
__main__.pyfile can now be executed directly by passing their name to the interpreter. The directory/zipfile is automatically inserted as the first entry insys.path. - The
int()type gained abit_lengthmethod that returns the number of bits necessary to represent its argument in binary. - The fields in
format()strings can now be automatically numbered. - The
string.maketrans()function is deprecated and is replaced by new static methods,bytes.maketrans()andbytearray.maketrans(). This change solves the confusion around which types were supported by the string module. Now,str,bytes, andbytearrayeach have their ownmaketransandtranslatemethods with intermediate translation tables of the appropriate type. - The syntax of the
withstatement now allows multiple context managers in a single statement. -
round(x, n)now returns an integer ifxis an integer. Previously it returned afloat. - Python now uses David Gay's algorithm for finding the shortest floating point representation that doesn't change its value.
- Added a
collections.Counterclass to support convenient counting of unique items in a sequence or iterable. - Added a new module,
tkinter.ttkfor access to the Tk themed widget set. The basic idea ofttkis to separate, to the extent possible, the code implementing a widget's behavior from the code implementing its appearance. - The
gzip.GzipFileandbz2.BZ2Fileclasses now support the context management protocol. - The
decimalmodule now supports methods for creating a decimal object from a binary float. - The
itertoolsmodule grew two new functions. Theitertools.combinations_with_replacement()function is one of four for generating combinatorics including permutations and Cartesian products. Theitertools.compress()function mimics its namesake from APL. Also, the existingitertools.count()function now has an optional step argument and can accept any type of counting sequence includingfractions.Fractionanddecimal.Decimal. -
collections.namedtuple()now supports a keyword argument rename which lets invalid fieldnames be automatically converted to positional names in the form_0,_1, etc. This is useful when the field names are being created by an external source such as a CSV header, SQL field list, or user input. - The
re.sub(),re.subn()andre.split()functions now accept aflagsparameter. - The
loggingmodule now implements a simplelogging.NullHandlerclass for applications that are not using logging but are calling library code that does. Setting-up a null handler will suppress spurious warnings such as "No handlers could be found for logger foo". - The
runpymodule which supports the-mcommand line switch now supports the execution of packages by looking for and executing a__main__submodule when a package name is supplied. - The
pdbmodule can now access and display source code loaded viazipimport(or any other conformant PEP 302 loader). -
functools.partialobjects can now be pickled. - Add
pydochelp topics for symbols so thathelp('@')works as expected in the interactive environment. - The
unittestmodule now supports skipping individual tests or classes of tests. And it supports marking a test as an expected failure, a test that is known to be broken, but shouldn't be counted as a failure on aTestResult. Also, tests for exceptions have been built out to work with context managers using thewithstatement. In addition, several new assertion methods were added includingassertSetEqual(),assertDictEqual(),assertDictContainsSubset(),assertListEqual(),assertTupleEqual(),assertSequenceEqual(),assertRaisesRegexp(),assertIsNone(), andassertIsNotNone(). - The
iomodule has three new constants for theseek()method:SEEK_SET,SEEK_CUR, andSEEK_END. -
sys.version_infotuple is now a named tuple. - The
nntplibandimaplibmodules now support IPv6. - The
picklemodule has been adapted for better interoperability with Python 2.x when used with protocol 2 or lower. The reorganization of the standard library changed the formal reference for many objects. For example,__builtin__.setin Python 2 is calledbuiltins.setin Python 3. This change confounded efforts to share data between different versions of Python. But now when protocol 2 or lower is selected, the pickler will automatically use the old Python 2 names for both loading and dumping. This remapping is turned-on by default but can be disabled with thefix_importsoption. An unfortunate but unavoidable side-effect of this change is that protocol 2 pickles produced by Python 3.1 won't be readable with Python 3.0. The latest pickle protocol, protocol 3, should be used when migrating data between Python 3.x implementations, as it doesn't attempt to remain compatible with Python 2.x. - A new module,
importlibwas added. It provides a complete, portable, pure Python reference implementation of theimportstatement and its counterpart, the__import__()function. It represents a substantial step forward in documenting and defining the actions that take place during imports.
Still looking for more? Browse the Discussions tab, where you can ask questions to the IronPython community.
🐍 IronPython