Return the default value for this option. For non-boolean flag options, ``default=True`` is treated as a sentinel meaning "activate this flag by default" and is resolved to :attr:`flag_value`. For example, with ``--upper/--lower`` feature switches where ``flag_value
(
self, ctx: Context, call: bool = True
)
| 3065 | return info_dict |
| 3066 | |
| 3067 | def get_default( |
| 3068 | self, ctx: Context, call: bool = True |
| 3069 | ) -> t.Any | t.Callable[[], t.Any] | None: |
| 3070 | """Return the default value for this option. |
| 3071 | |
| 3072 | For non-boolean flag options, ``default=True`` is treated as a sentinel |
| 3073 | meaning "activate this flag by default" and is resolved to |
| 3074 | :attr:`flag_value`. For example, with ``--upper/--lower`` feature |
| 3075 | switches where ``flag_value="upper"`` and ``default=True``, the default |
| 3076 | resolves to ``"upper"``. |
| 3077 | |
| 3078 | .. caution:: |
| 3079 | This substitution only applies to non-boolean flags |
| 3080 | (:attr:`is_bool_flag` is ``False``). For boolean flags, ``True`` is |
| 3081 | a legitimate Python value and ``default=True`` is returned as-is. |
| 3082 | |
| 3083 | .. versionchanged:: 8.3.3 |
| 3084 | ``default=True`` is no longer substituted with ``flag_value`` for |
| 3085 | boolean flags, fixing negative boolean flags like |
| 3086 | ``flag_value=False, default=True``. |
| 3087 | """ |
| 3088 | value = super().get_default(ctx, call=False) |
| 3089 | |
| 3090 | # Resolve default=True to flag_value lazily (here instead of |
| 3091 | # __init__) to prevent callable flag_values (like classes) from |
| 3092 | # being instantiated by the callable check below. |
| 3093 | if value is True and self.is_flag and not self.is_bool_flag: |
| 3094 | value = self.flag_value |
| 3095 | elif call and callable(value): |
| 3096 | value = value() |
| 3097 | |
| 3098 | return value |
| 3099 | |
| 3100 | def get_error_hint(self, ctx: Context | None) -> str: |
| 3101 | result = super().get_error_hint(ctx) |
no outgoing calls