warnings.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (c) "Neo4j"
  2. # Neo4j Sweden AB [https://neo4j.com]
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # https://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from __future__ import annotations
  16. import typing as t
  17. from ._debug import NotificationPrinter
  18. if t.TYPE_CHECKING:
  19. from ._work.summary import SummaryNotification
  20. __all__ = [
  21. "Neo4jDeprecationWarning",
  22. "Neo4jWarning",
  23. ]
  24. class Neo4jWarning(Warning):
  25. """
  26. Warning emitted for notifications sent by the server.
  27. Which notifications trigger a warning can be controlled by a
  28. configuration option: :ref:`driver-warn-notification-severity-ref`
  29. **This is experimental** (see :ref:`filter-warnings-ref`).
  30. It might be changed or removed any time even without prior notice.
  31. :param notification: The notification that triggered the warning.
  32. :param query: The query for which the notification was sent.
  33. If provided, it will be used for a more detailed warning message.
  34. .. versionadded:: 5.21
  35. .. seealso:: :ref:`development-environment-ref`
  36. """
  37. #: The notification that triggered the warning.
  38. notification: SummaryNotification
  39. def __init__(
  40. self,
  41. notification: SummaryNotification,
  42. query: str | None = None,
  43. ) -> None:
  44. msg = str(NotificationPrinter(notification, query))
  45. super().__init__(msg)
  46. self.notification = notification
  47. class Neo4jDeprecationWarning(Neo4jWarning, DeprecationWarning):
  48. """
  49. Warning emitted for deprecation notifications sent by the server.
  50. .. note::
  51. This warning is a subclass of :class:`DeprecationWarning`.
  52. This means that Python will not show this warning by default.
  53. **This is experimental** (see :ref:`filter-warnings-ref`).
  54. It might be changed or removed any time even without prior notice.
  55. :param notification: The notification that triggered the warning.
  56. .. versionadded:: 5.21
  57. """