instructor icon indicating copy to clipboard operation
instructor copied to clipboard

Update mode.py to warn in `Mode.FUNCTIONS` access vs. in `__new__`

Open boydgreenfield opened this issue 9 months ago • 2 comments

Currently, any import of instructor raises a DeprecationWarning. This is noisy and also makes it impossible to have test suites raise an error on DeprecationWarning. Example code:

import warnings
warnings.simplefilter("default")

import instructor  # raises `DeprecationWarning: FUNCTIONS is deprecated and will be removed in future versionss enum_member = enum_class._new_member_(enum_class, *args)`

:rocket: This description was created by Ellipsis for commit 90edc70cefc2ee9f30870f5f510ad2f33ace54eb

Summary:

This PR moves the deprecation warning for FUNCTIONS in Mode class to only trigger when accessed, reducing import-time noise.

Key points:

  • Moved DeprecationWarning for FUNCTIONS from __new__ to __getattribute__ in a Mode metaclass.
  • Reduces warning noise at import time.
  • Allows better handling of DeprecationWarning in test suites.

Generated with :heart: by ellipsis.dev


:rocket: This description was created by Ellipsis for commit 9ef6f1aa5d17baeada3febcc5fb7ef98813d86ac

Summary:

This PR moves the deprecation warning for FUNCTIONS in the Mode class to only trigger when accessed, reducing import-time noise.

Key points:

  • Moved DeprecationWarning for FUNCTIONS from __new__ to __getattribute__ in Mode class using _WarnOnFunctionsAccessEnumMeta metaclass.
  • Reduces warning noise at import time.
  • Allows better handling of DeprecationWarning in test suites.

Generated with :heart: by ellipsis.dev

boydgreenfield avatar May 17 '24 20:05 boydgreenfield