'Why does the python strtobool method return an Int instead of a bool?
strtobool is a great function from the python standard library.
However it returns an int instead of a bool, requiring wrapping it eg bool(strtobool(x)).
On the surface, this seems unintuitive and misleading, and it's very easy to forget especially in a loosely typed language like python.
What were the design decisions which led to this approach?
Solution 1:[1]
It's probably anyone's guess at this point. distutils is deprecated and being removed in Python 3.12, as per PEP 632, and regarding strtobool specifically, the advice is to re-implement it by yourself:
For these functions, and any others not mentioned here, you will need to reimplement the functionality yourself. The legacy documentation can be found at https://docs.python.org/3.9/distutils/apiref.html
distutils.dir_util.create_treedistutils.util.change_rootdistutils.util.strtobool
So, in short, don't use it, and in your version, feel free to return a proper bool instead.
Solution 2:[2]
I have no idea why strtobool() returns an int. An int can be used as a bool in most situations, however, if you actually need a bool then I would recommend that you create a new function within your scripts that looks something like this:
from distutils.util import strtobool as stb
def strtobool(string: str)->bool: return bool(stb(string))
This allows calling strtobool() so it returns an bool.
Solution 3:[3]
The only argument on the Terraform side is aws_db_instance's replicate_source_db
replicate_source_db - (Optional) Specifies that this resource is a Replicate database, and to use this value as the source database. This correlates to the identifier of another Amazon RDS Database to replicate (if replicating within a single region) or ARN of the Amazon RDS Database to replicate (if replicating cross-region). Note that if you are creating a cross-region replica of an encrypted database you will also need to specify a kms_key_id.
The replicate_source_db should have the ID or ARN of the source database.
resource "aws_db_instance" "oracle" {
# ... other arguments
}
resource "aws_db_instance" "oracle_replicant" {
# ... other arguments
replicate_source_db = aws_db_instance.oracle.id
}
Reference
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | amiasato |
| Solution 2 | |
| Solution 3 | SomeGuyOnAComputer |
