Skip to content

Instantly share code, notes, and snippets.

@fillest
Last active October 3, 2023 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fillest/dce93a03f2e5a865ec5457abbe5ce297 to your computer and use it in GitHub Desktop.
Save fillest/dce93a03f2e5a865ec5457abbe5ce297 to your computer and use it in GitHub Desktop.

grouped by versions (3.0 to 3.10).
most important is marked with bold.


(https://docs.python.org/3/whatsnew/3.0.html)

  • binary data and Unicode
    Python 3.0 uses the concepts of text and (binary) data.
    All text is Unicode ("...")
    b"..." literals for binary data.
    any attempt to mix text and data in Python 3.0 raises TypeError
    >The rules for translating a Unicode string into a sequence of bytes are called a character encoding, or just an encoding.
    str.encode() to go from str to bytes, bytes.decode() to go from bytes to str
    basestring was removed. Use str instead -- again, bytes are separate
    Files opened as text files (still the default mode for open()) always use an encoding to map between strings (in memory) and bytes (on disk). Binary files (opened with a b in the mode argument) always use bytes in memory.
    The default source encoding is now UTF-8.
    Python’s re module defaults to the re.UNICODE flag rather than re.ASCII. This means, for instance, that r"\w" matches Unicode word characters, not just ASCII letters.
  • Exception chaining raise [expr [from expr]]
  • print()
  • dict methods .keys(), .items() and .values() return “views” instead of lists
  • removed dict.iter*() methods
  • map() and filter() return iterators
  • range() now behaves like xrange() used to behave
  • 1/2 returns a float. Use 1//2 to get the truncating behavior.
  • Octal literals 0720 -> 0o720
  • Named parameters occurring after *args in the parameter list must be specified using keyword syntax in the call. You can also use a bare * in the parameter list to indicate that you don’t accept a variable-length argument list, but you do have keyword-only arguments.
  • Extended Iterable Unpacking e.g. (a, *rest, b) = range(5)
  • Set literals, e.g. {1, 2}, Set comprehensions
  • Tuple parameter unpacking removed. You can no longer write def foo(a, (b, c)): .... Use def foo(a, b_c): b, c = b_c instead.
  • Classic classes are gone.
  • The io module is now the standard way of doing file I/O. The built-in open() function is now an alias for io.open()
  • In Python 3.0, the accelerated versions are considered implementation details of the pure Python versions. Users should always import the standard version, which attempts to import the accelerated version and falls back to the pure Python version.
  • You can now invoke super() without arguments
  • (less important)
    • BaseException
    • The StringIO module has been turned into a class in the io module.
    • The only acceptable syntax for relative imports is from .[module] import name. All import forms not starting with . are interpreted as absolute imports. (PEP 328)
    • Dictionary comprehensions (already in 2.7)
    • new convention for specifying a metaclass
    • Using nonlocal x you can now assign directly to a variable in an outer (but non-global) scope.
    • long renamed to int

(https://docs.python.org/3/whatsnew/3.1.html)

  • (less important)
    • Directories and zip archives containing a __main__.py file can now be executed directly by passing their name to the interpreter.
    • The runpy module which supports the -m command line switch now supports the execution of packages by looking for and executing a __main__ submodule when a package name is supplied.

(https://docs.python.org/3/whatsnew/3.2.html)

(https://docs.python.org/3/whatsnew/3.3.html)

  • yield from https://stackoverflow.com/q/9708902/1183239
  • venv
  • OSError subclasses e.g. FileNotFoundError, ConnectionRefusedError
  • datetime.timestamp()
  • time.monotonic()
  • clock_gettime(), perf_counter()
  • (less important)
    • signal.pthread_kill If signalnum is 0, then no signal is sent, but error checking is still performed; this can be used to check if the target thread is still running.

(https://docs.python.org/3/whatsnew/3.4.html)

  • asyncio
  • pathlib
  • tracemalloc
  • (less important)
    • enum
    • statistics
    • gc.get_stats()
    • multiprocessing now has an option to avoid using os.fork on Unix
    • pickle protocol 4.
    • regex.fullmatch()
    • main_thread()
    • Customization of CPython Memory Allocators

(https://docs.python.org/3/whatsnew/3.5.html)

  • Type Hints
  • additional unpacking generalizations
    d3 = {**d1, **d2}
    print(*[1], *[2], 3, *[4, 5])
    fn(**{'a': 1, 'c': 3}, **{'b': 2, 'd': 4})
    [*range(4), 4]
    {'x': 1, **{'y': 2}}
  • subprocess.run()
  • from __future__ import generator_stop
  • Circular imports involving relative imports are now supported

(https://docs.python.org/3/whatsnew/3.6.html)

  • multiprocessing.shared_memory
  • Assignment expressions (the “walrus operator”, :=) to assign values to variables as part of an expression.
  • (less important)
    • Positional-only parameters
    • Parallel filesystem cache for compiled bytecode files
    • f'{cos(radians(theta))=:.3f}' expands to e.g. 'cos(radians(theta))=0.866'
    • Runtime Audit Hooks
    • Pickle protocol 5
    • Dict and dictviews are now iterable in reversed insertion order using reversed()
    • importlib.metadata module provides (provisional) support for reading metadata from third-party packages. For example, it can extract an installed package’s version number, list of entry points
    • sys.unraisablehook()
    • threading.excepthook()
  • Merge (|) and update (|=) operators have been added to the built-in dict class.
  • str.removeprefix(prefix) and str.removesuffix(suffix). Corresponding bytes, bytearray, and collections.UserString methods have also been added.
  • Type Hinting Generics in Standard Collections
  • zoneinfo, tzdata change
  • stdlib tomllib: For parsing TOML
  • >the interpreter will now point to the exact expression that caused the error
  • good typing improvements https://docs.python.org/3.11/whatsnew/3.11.html#new-features-related-to-type-hints
  • Exception Groups and except* https://peps.python.org/pep-0654/
  • Python 3.11 is between 10-60% faster than Python 3.10.

  • The add_note() method is added to BaseException. It can be used to enrich exceptions with context information that is not available at the time when the exception is raised.
  • Starred unpacking expressions can now be used in for statements.

  • hashlib.file_digest()
  • logging.getLevelNamesMapping()
  • operator.call
  • pathlib glob() and rglob() return only directories if pattern ends with a pathname components separator
  • On Unix, time.sleep() now uses the clock_nanosleep() or nanosleep() function, if available
  • significantly improved typing
  • improved f-strings
  • per-interpreter GIL >currently only available through the C-API, though a Python API is anticipated for 3.13
  • new API for profilers, debuggers, and other tools ... you only pay for what you use, providing support for near-zero overhead debuggers and coverage tools
  • buffer protocol accessible in Python
  • Improved Error Messages
  • CPython support for the Linux perf profiler
  • itertools.batched()
  • sqlite3 module can be invoked as a script, using the interpreter’s -m switch, in order to provide a simple SQLite shell
  • uuid module can be executed as a script from the command line
  • datetime: datetime.datetime’s utcnow() and utcfromtimestamp() are deprecated and will be removed in a future version. Instead, use timezone-aware objects to represent datetimes in UTC: respectively, call now() and fromtimestamp() with the tz parameter set to datetime.UTC.
  • stop installing setuptools in environments created by venv
  • Replace the builtin hashlib implementations of SHA1, SHA3, SHA2-384, SHA2-512, and MD5 with formally verified code from the HACL* project. These builtin implementations remain as fallbacks that are only used when OpenSSL does not provide them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment