Log deprecation warning. Args: name (str): name of the deprecated item. text (str, optional): information about the deprecation. eos (str, optional): end of service date such as "YYYY-MM-DD". max_num_warnings (int, optional): the maximum number of times to p
(name="", text="", eos="", max_num_warnings=None)
| 80 | |
| 81 | |
| 82 | def log_deprecated(name="", text="", eos="", max_num_warnings=None): |
| 83 | """ |
| 84 | Log deprecation warning. |
| 85 | |
| 86 | Args: |
| 87 | name (str): name of the deprecated item. |
| 88 | text (str, optional): information about the deprecation. |
| 89 | eos (str, optional): end of service date such as "YYYY-MM-DD". |
| 90 | max_num_warnings (int, optional): the maximum number of times to print this warning |
| 91 | """ |
| 92 | assert name or text |
| 93 | if eos: |
| 94 | eos = "after " + datetime(*map(int, eos.split("-"))).strftime("%d %b") |
| 95 | if name: |
| 96 | if eos: |
| 97 | warn_msg = "%s will be deprecated %s. %s" % (name, eos, text) |
| 98 | else: |
| 99 | warn_msg = "%s was deprecated. %s" % (name, text) |
| 100 | else: |
| 101 | warn_msg = text |
| 102 | if eos: |
| 103 | warn_msg += " Legacy period ends %s" % eos |
| 104 | |
| 105 | if max_num_warnings is not None: |
| 106 | if _DEPRECATED_LOG_NUM[warn_msg] >= max_num_warnings: |
| 107 | return |
| 108 | _DEPRECATED_LOG_NUM[warn_msg] += 1 |
| 109 | logger.warn("[Deprecated] " + warn_msg) |
| 110 | |
| 111 | |
| 112 | def deprecated(text="", eos="", max_num_warnings=None): |