OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

iterate over IntFlag enumeration using iter differs in python 3.8 and 3.12.4

  • Thread starter Thread starter mhanuel
  • Start date Start date
M

mhanuel

Guest
I have the following working in python 3.8.1

Code:
@unique
class Encoder(IntFlag):
    # H1 sensor signal
    H1 = 0x00
    # H2 sensor signal
    H2 = 0x01
    # H3 sensor signal
    H3 = 0x02

Then I am trying to catch with an assert if the value is not within the enum, i.e.

Code:
from enum import unique, IntFlag
signal = Encoder.H1
assert signal in iter(Encoder), f"Valid Encoder line is integer 0 to 2 inclusive."

I noticed on python 3.8, the signal in iter(Encoder) returns True but False in python 3.12.4

enter image description here

It might be a hange in some version from 3.8.1 to 3.12.4 but I am not sure where to star looking for getting this working in both.
<p>I have the following working in python 3.8.1</p>
<pre><code>@unique
class Encoder(IntFlag):
# H1 sensor signal
H1 = 0x00
# H2 sensor signal
H2 = 0x01
# H3 sensor signal
H3 = 0x02
</code></pre>
<p>Then I am trying to catch with an assert if the value is not within the enum, i.e.</p>
<pre><code>from enum import unique, IntFlag
signal = Encoder.H1
assert signal in iter(Encoder), f"Valid Encoder line is integer 0 to 2 inclusive."
</code></pre>
<p>I noticed on python 3.8, the signal in iter(Encoder) returns True but False in python 3.12.4</p>
<p><a href="https://i.sstatic.net/1Rrk2u3L.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1Rrk2u3L.png" alt="enter image description here" /></a></p>
<p>It might be a hange in some version from 3.8.1 to 3.12.4 but I am not sure where to star looking for getting this working in both.</p>
 
Top