Must Know Features Of Python 3.10

Must know features of Python 3.10

We all know that Python is a widely used general purpose, high level programming language. Initially it was designed by Guido van Rossum in 1991 and developed by Python software foundation. Mainly it was developed for emphasis on code readability and its syntax allows developers to express concepts with less lines of code. Python programming language  allow you to work quickly and efficiently integrate systems.

Recently python 3.10 was released. So if you are thinking to develop web solution with Python, you must know it’s new features. Let’s have a look at amazing features of Python 3.10.

What’s New In Python 3.10?

Python logo

1. PEP 563: Postponed Evaluation Of Annotations Becomes Default-

In previous version, Python 3.7, postponed evaluation of annotations was added, to be enabled with from_future_import annotations directive. Now, in 3.10, it became default behavior, without that future directive. All annotations stored in _annotations_ will be strings. If required, annotations can resolved at runtime using typing.get_type_hints(). And, inspect.signature() will try to resolve types from now on, and when it fails, fall back to show the string annotations.

  • Views that are returned by dict.keys(), dict.values() and dict.items() have mapping attribute that gives types.MappingProxyType object wrapping the original dictionary.
  • Int type has new method int.bit_count(), it returns the number of ones in binary expansion of a given integer, known as population count.
  • Now the zip() function has an optional strict flag, used to require all iterables have an equal length.

2. PEP604: New Type Union Operator-

Union operator was included that allows the syntax X | Y and provides a clear way of expressing ‘either type X or type Y’ rather than using typing.Union. In old versions of Python, typing.Union was used to apply hint for functions accepting arguments of multiple types.

def square(number: Union[int, float]) -> Union[int, float]:
return number ** 2

But, now type hints can be written in clear manner:

def square(number: int | float) -> int | float:
return number ** 2

3. PEP 613: TypeAlias Annotation-

PEP 484 came with a concept of type alias, only need them to be top- level unannotated assignments. Sometimes, this lucidity made it complicated for type checkers to distinguish between type aliases and ordinary assignments, specifically when forward references or invaid types are included.

StrCache = 'Cache[str]'  ## a type alias
LOG_PREFIX = 'LOG[DEBUG]'  ## a module constant

Now typing module has a special annotation TypeAlias for declaring type aliases more explicitly.

StrCache: TypeAlias = 'Cache[str]'  ## a type alias
LOG_PREFIX = 'LOG[DEBUG]'  ## a module constant

4. Optimizations-

  • Now the ruppy module imports fewer modules. Python3 -m module-name command startup time is 1.3x faster in average.
  • Constructors bytes(), str() and bytearray() are now faster.
  • Now, the LOAD_ATTR instruction uses “per opcode cache” mechanism. It is nearly 36% faster now. 
  • While building Python with –enable-optimizations, now – fno-semantic-interposition is added to both the compile and link line. This can rapidly proceed builds of the Python interpreter created with –enable-shared with gcc by up to 30%. 

5. Removed-

  • The ParserBase.error() method from private and undocumented _markupbase module has removed. html.parser.HTMLParser is the only subclass of ParserBase and its error()implementation has already removed.
  • Some special methods like _int_, _float_, _floordiv_, _mod_, _divmod_, _rfloordiv_, _rmod_ and _rdivmod_ are removed. 
  • unicodedata.ucnhash_CAPI attribute is now removed. Related private _PyUnicode_Name_CAPI structure moved to internal C API.

6. Deprecated-

  • In this release, there will be a concerted effort to start cleaning up old import semantics that were kept for Python 2.7 compatibility. Especially, find_loader()/find_module() (superseded by find_spec()), load_module() (superseded by exec_module()), module_repr() (which the import system takes care of for you), the __package__ attribute (superseded by __spec__.parent), the __loader__ attribute (superseded by __spec__.loader), and the __cached__ attribute (superseded by __spec__.cached) will slowly be removed (as well as other classes and methods in importlib). ImportWarning or DeprecationWarning will be raised as proper to help recognize code which needs updating during this transition.

7. Improved Modules-


Now, encodings.normalize_encoding() ignores non-ASCII characters.


Added os.cpu_count() support for VxWorks RTOS.


Add base64.b32hexdecode() and base64.b32hexencode() to support Base32 Encoding with Extended Hex Alphabet.


Add function codecs.unregister() to unregister a codec search function.


root_dir and dir_fd added parameters in glob() an iglob(). This allows to specify the root directory for searching.


Reintroduced types.NotImplementedType, types.EllipsisType, types.NoneType classes, providing a new set of types readily interpretable by type checkers.


When creating shelves, now, this module uses by default pickle.DEFAULT_PROTOCOL rather than pickle protocol 3.

Wrap up-

There are some more new features in Python 3.10. If you’re thinking of developing a web solution with Python, you must know these important new features. We are here to help you through our skilled developers. You can hire Python developers of Solace team for effective development. Connect with solace and get a free quote to develop a web solution with advanced features. We will be happy to help you.

Related Post