r"""Return the value of a dialect-specific option, or *else_* if this dialect does not register the given argument. This is useful for DDL compilers that may be inherited by third-party dialects whose ``construct_arguments`` do not include the same set of keys as the
(
self,
dialect: Dialect,
argument_name: str,
*,
else_: Any = None,
deprecated_fallback: Optional[str] = None,
)
| 496 | ] |
| 497 | |
| 498 | def get_dialect_option( |
| 499 | self, |
| 500 | dialect: Dialect, |
| 501 | argument_name: str, |
| 502 | *, |
| 503 | else_: Any = None, |
| 504 | deprecated_fallback: Optional[str] = None, |
| 505 | ) -> Any: |
| 506 | r"""Return the value of a dialect-specific option, or *else_* if |
| 507 | this dialect does not register the given argument. |
| 508 | |
| 509 | This is useful for DDL compilers that may be inherited by |
| 510 | third-party dialects whose ``construct_arguments`` do not |
| 511 | include the same set of keys as the parent dialect. |
| 512 | |
| 513 | :param dialect: The dialect for which to retrieve the option. |
| 514 | :param argument_name: The name of the argument to retrieve. |
| 515 | :param else\_: The value to return if the argument is not present. |
| 516 | :param deprecated_fallback: Optional dialect name to fall back to |
| 517 | if the argument is not present for the current dialect. If the |
| 518 | argument is present for the fallback dialect but not the current |
| 519 | dialect, a deprecation warning will be emitted. |
| 520 | |
| 521 | """ |
| 522 | |
| 523 | registry = DialectKWArgs._kw_registry[dialect.name] |
| 524 | if registry is None: |
| 525 | return else_ |
| 526 | |
| 527 | if argument_name in registry.get(self.__class__, {}): |
| 528 | if ( |
| 529 | deprecated_fallback is None |
| 530 | or dialect.name == deprecated_fallback |
| 531 | ): |
| 532 | return self.dialect_options[dialect.name][argument_name] |
| 533 | |
| 534 | # deprecated_fallback is present; need to look in two places |
| 535 | |
| 536 | # Current dialect has this option registered. |
| 537 | # Check if user explicitly set it. |
| 538 | if ( |
| 539 | dialect.name in self.dialect_options |
| 540 | and argument_name |
| 541 | in self.dialect_options[dialect.name]._non_defaults |
| 542 | ): |
| 543 | # User explicitly set this dialect's option - use it |
| 544 | return self.dialect_options[dialect.name][argument_name] |
| 545 | |
| 546 | # User didn't set current dialect's option. |
| 547 | # Check for deprecated fallback. |
| 548 | elif ( |
| 549 | deprecated_fallback in self.dialect_options |
| 550 | and argument_name |
| 551 | in self.dialect_options[deprecated_fallback]._non_defaults |
| 552 | ): |
| 553 | # User set fallback option but not current dialect's option |
| 554 | warn_deprecated( |
| 555 | f"Using '{deprecated_fallback}_{argument_name}' " |