Python added support for type hints in 3.5. These are not typing as you may be used to in other languages
since they have no effect on the compilation to bytecode nor at runtime, but rather hints for the
(tools of the) developer.
The code above doesn’t fail when you call print_int("foo") even though n is “typed” as an int. This is because
this n: int is just a hint.
While you can check for type issues by running mypy by hand, type hints become really
powerful when your editor/IDE supports them.
Types for collections can specify the inner types: a list (List) that contains strings (str) would be List[str].
In the snippet above, the last line is highlighted as an error in any good IDE, and mypy would complain about it.
Other container types exist as well, and they can be nested:
Given List[x], Collection[x], Sequence[x] and other Set[x], one would expect Tuple[x] to be a hint for a tuple
that contains x. Well… no.
This is confusing at first, but Tuple[str] types a tuple of a single element of type str. To add
more elements, you need to type them as well: a pair of ints would be Tuple[int, int], while a triplet of a string,
a float and a boolean would be Tuple[str, int, bool].
While tuples can be used as sequences (e.g. for immutable/hashable equivalents to lists), I’d argue that their primary
use is for fixed-length representations, such as pairs of results:
In this snippet, match_object returns a tuple of a list of floats and a list of integers
(aka Tuple[List[float], List[int]]).
If you still want to type arbitrary-length homogeneous tuples, there’s a syntax for that: Tuple[int, ...]
types a tuple of any length, including 0, that contains only int elements (and yes, ... is valid in Python).
While working with Magento 2.3.6 on Bixoto I hit a weird issue: the
bin/magento command-line tool was always eating all the RAM, even with a simple command:
The issue, as weird as it sounds, is an empty configuration value that causes Magento to end up in
an infinite loop.
When I installed Magento on my local machine, I deactivated HTTPS by setting web/secure/base_url
to NULL in the table core_config_data. This alone is the cause of the issue.
Check in MySQL:
If this shows a line with a NULL value, either delete it or replace it with some non-null value:
This has been reported to Magento but was closed because “it’s not a bug”. I don’t think
falling in an infinite loop on --help because some config value is NULL should really be a
normal behavior, but at least now you know how to solve it.
While following a tutorial to install Virtualbox in order to have docker working on macOS, I
hit an issue where the docker-machine create command fails with an error that looks like this:
If you search on the Web, everybody says you have to open the Security & Privacy settings window
and allow the Oracle kernel extensions to run. But I didn’t have it. I tried uninstalling
Virtualbox, re-installing through the official website, reboot, uninstall, re-install with
brew cask but I always had the issue. Some people reported having a failed Virtualbox
installation but mine seemed ok.