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?
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.
Know more at- [https://solaceinfotech.com/blog/must-know-features-of-python-3-10/]
Top comments (0)