PathVariable.PathIsDirCreate does not allow for "required" arguments
This issue was originally created at: 2012-03-23 00:23:22.
This issue was reported by: mortoray.
mortoray said at 2012-03-23 00:23:22
If you create a variable with the PathVariable.PathIsDir or PathIsDirCreate and specify None as the default, the default will be accepted. As None is not a valid path it should not be accepted. This is especially troublesome since the variable won't even be registered in the environment, meaning it is completely undefined (leading to KeyErrors if you attempt to use it directly).
For example:
PathVariable('PREFIX', 'Installation prefix', None, PathVariable.PathIsDirCreate),
The intent is to force the user to specify a PREFIX (no default). The validator will however accept the default None.
mortoray said at 2012-03-23 00:36:13
Hmm, I think I see the problem, it is more fundamental than this. It appears that there is no way to make a required variable. The default of None completely bypasses the validator, as though it states the variable is optional. This is odd because the other defaults are subjected to the validation. So this problem with None applies to all variables.
This would mean that there is no way to create a required variable which does not have a default.
First off, there's documented behavior that seems to be at odds with the expectation here:
If
defaultisNoneand a value is not specified, the construction variable will not be added to the construction environment.
It works the same if you explicitly specify a value of None when that is the default - the variable simply isn't added.
So:
This is especially troublesome since the variable won't even be registered in the environment, meaning it is completely undefined
yes, that's how it works, and how it's documented.
This would mean that there is no way to create a required variable which does not have a default.
So unless there's an objection, I'd like to either flip this from "bug" to "enhancement" - assuming anyone else thinks it's a good idea to provide a way to indicate a variable as must-supply (there seem to be other ways to implement that, like give a nonsensical default and elsewhere bail out if that's the value, which admittedly can be a bit of a pain) - or just close the issue. I just don't think "behaves as documented" makes it a bug.
updated the title a bit