Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: no __contains__ on StrEnum until 3.12 #4933

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

wssheldon
Copy link
Contributor

@wssheldon wssheldon commented Jul 8, 2024

Even if you implement __contains__ you still get the following error:

<stdin>:1: DeprecationWarning: in 3.12 __contains__ will no longer raise TypeError, but will return True or
False depending on whether the value is a member or the value of a member
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/wshel/.pyenv/versions/3.11.2/lib/python3.11/enum.py", line 745, in __contains__
    raise TypeError(
TypeError: unsupported operand type(s) for 'in': 'str' and 'EnumType'
    def __contains__(self, other):
        """
        Returns True if self has at least the same flags set as other.
        """
        if not isinstance(other, self.__class__):
            raise TypeError(
                "unsupported operand type(s) for 'in': %r and %r" % (
                    type(other).__qualname__, self.__class__.__qualname__))
        return other._value_ & self._value_ == other._value_
(dispatch) wshel@wills-mbp dispatch % python3 
Python 3.11.2 (main, Mar  6 2023, 17:43:14) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from dispatch.enums import DispatchEnum
>>> from dispatch.plugins.dispatch_slack.enums import SlackAPIErrorCode
>>> slack_error = "this_is_retryable"
>>> slack_error not in SlackAPIErrorCode
<stdin>:1: DeprecationWarning: in 3.12 __contains__ will no longer raise TypeError, but will return True or
False depending on whether the value is a member or the value of a member
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/wshel/.pyenv/versions/3.11.2/lib/python3.11/enum.py", line 745, in __contains__
    raise TypeError(
TypeError: unsupported operand type(s) for 'in': 'str' and 'EnumType'
>>> exit()



(dispatch) wshel@wills-mbp dispatch % python3
Python 3.11.2 (main, Mar  6 2023, 17:43:14) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from dispatch.plugins.dispatch_slack.enums import SlackAPIErrorCode
>>> exit()
(dispatch) wshel@wills-mbp dispatch % python3
Python 3.11.2 (main, Mar  6 2023, 17:43:14) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from dispatch.plugins.dispatch_slack.enums import SlackAPIErrorCode
>>> slack_error = "this_is_retryable"
>>> slack_error not in SlackAPIErrorCode
<stdin>:1: DeprecationWarning: in 3.12 __contains__ will no longer raise TypeError, but will return True or
False depending on whether the value is a member or the value of a member
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/wshel/.pyenv/versions/3.11.2/lib/python3.11/enum.py", line 745, in __contains__
    raise TypeError(
TypeError: unsupported operand type(s) for 'in': 'str' and 'EnumType'
>>> slack_error not in SlackAPIErrorCode.__members__.values()
True

@wssheldon wssheldon added the bug Something isn't working label Jul 8, 2024
@wssheldon wssheldon requested a review from jschroth July 8, 2024 23:41
@wssheldon wssheldon self-assigned this Jul 8, 2024
@wssheldon wssheldon merged commit b00b5b2 into master Jul 8, 2024
10 checks passed
@wssheldon wssheldon deleted the bugfix/slack-make-call branch July 8, 2024 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant