configuration_mixin.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  2. # For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
  3. # Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
  4. from __future__ import annotations
  5. import warnings
  6. from typing import Any
  7. from pylint.config.option_manager_mixin import OptionsManagerMixIn
  8. from pylint.config.options_provider_mixin import ( # type: ignore[attr-defined]
  9. OptionsProviderMixIn,
  10. )
  11. class ConfigurationMixIn(OptionsManagerMixIn, OptionsProviderMixIn): # type: ignore[misc]
  12. """Basic mixin for simple configurations which don't need the
  13. manager / providers model.
  14. """
  15. def __init__(self, *args: Any, **kwargs: Any) -> None:
  16. # TODO: 3.0: Remove deprecated class
  17. warnings.warn(
  18. "ConfigurationMixIn has been deprecated and will be removed in pylint 3.0",
  19. DeprecationWarning,
  20. stacklevel=2,
  21. )
  22. if not args:
  23. kwargs.setdefault("usage", "")
  24. OptionsManagerMixIn.__init__(self, *args, **kwargs)
  25. OptionsProviderMixIn.__init__(self)
  26. if not getattr(self, "option_groups", None):
  27. self.option_groups: list[tuple[str, str]] = []
  28. for _, optdict in self.options:
  29. try:
  30. gdef = (optdict["group"].upper(), "")
  31. except KeyError:
  32. continue
  33. if gdef not in self.option_groups:
  34. self.option_groups.append(gdef)
  35. self.register_options_provider(self, own_group=False)