33rd Week of 2021
Computer Science⚑
GNULinux⚑
(../computer_science/gnu_linux/bash.md)⚑
-
New: Remove an environment variable.
To remove an exported environment variable use:
unset VARIABLE
Programming⚑
(../python_basics.md)⚑
-
New: Abstract base classes.
(https://docs.python.org/3/glossary.html#term-abstract-base-class) in Python, as outlined in (https://www.python.org/dev/peps/pep-3119).
-
New: Enum.
An enumeration is a set of symbolic names (members) bound to unique, constant values. Within an enumeration, the members can be compared by identity, and the enumeration itself can be iterated over.
-
New: Custom exceptions.
To provide more insightful error messages related to our code, we can create custom exceptions. For example:
class ColorError(ValueError): def __init__(self, color): message = f"Invalid color {color}." super().__init__(message)
-
New: String remove prefix suffix methods.
str.removeprefix(prefix)
: If the string starts with the prefix string, returnstr
. Otherwise, return a copy of the original string.str.removesuffix(suffix)
: If the string ends with the suffix string and that suffix is not empty, returnstr
. Otherwise, return a copy of the original string.
-
New: Current local date and time.
-
New: TypedDict.
Special construct to add type hints to a dictionary. At runtime it is a plain
dict
.Example:
class Point2D(TypedDict): x: int y: int label: str a: Point2D = {'x': 1, 'y': 2, 'label': 'good'} # OK b: Point2D = {'z': 3, 'label': 'bad'} # Fails type check
(../computer_science/programming/python/docstrings.md)⚑
-
New: Python docstrings.
A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the
__doc__
special attribute of that object. See (https://www.python.org/dev/peps/pep-0257/)
(../computer_science/programming/python/mypy.md)⚑
-
New: Mypy.
(https://mypy.readthedocs.io/en/stable/) is a static type checker for Python.
-
New: Ignore line for type checking.
To ignore type checking in one particular line of the code, add the comment
# type: ignore
at the end of that line
(../computer_science/programming/python/pydantic.md)⚑
-
New: Pydantic.
(https://pydantic-docs.helpmanual.io/): data validation and settings management using python type annotations.
Enforces type hints at runtime, and provides user friendly errors when data is invalid.
-
New: Validators.
Custom validation and complex relationships between objects can be achieved using the
validator
decorator. -
New: Validators advanced use.
-
New: Root_validator.
Validation can also be performed on the entire model's data.
(../computer_science/programming/python/pytest.md)⚑
-
New: Coverage.py.
To see which parts of your code are executed when running the tests, you can use (https://coverage.readthedocs.io/).
(../computer_science/programming/python/requests.md)⚑
-
New: Python requests library.
(https://docs.python-requests.org/en/master/) is an elegant and simple HTTP library for Python, built for human beings.
(../computer_science/programming/python/snippets.md)⚑
-
New: Find in dictionary.
Find first element in dictionary that satisfies a condition:
next(item for item in {dict} if {{ condition }})
Other⚑
-
New: Breakpoint().
Since Python 3.7, we can just call
breakpoint()
and this will import (https://docs.python.org/3/library/pdb.html) (or the debugger defined in the environment variablePYTHONBREAKPOINT
) and set the breakpoint in that part of the code. This will stop the program execution once the breakpoint is reached. Then, an interactive console while appear. -
New: Order of abstractmethod classmethod.
Use
@abstractmethod
beforeclassmethod
. See (https://bugs.python.org/issue16267).