[issue30545] Enum equality across modules: comparing objects instead of values

2018-08-12 Thread Markus Wegmann


Markus Wegmann  added the comment:

Hi Ethan

> Your Enum example in flawless is not an IntEnum, so the error (unable to add 
> an integer to None) seems entirely unrelated.

The TypeError is just a consequence of the faulty Enum identity comparison some 
lines before. I mentioned the TypeError so you can verify whether your Python 
version takes the same program flow.


I also did further research. The Enum's are definitely different regarding the 
module path -- the instance comparison will therefore return False. I checked 
__module__ + __qualname__:

`flora_tools.radio_configuration.RadioModem.LORA`

vs.

`radio_configuration.RadioModem.LORA`


The cause is the wrong import statement in `flora_tools/codegen/codegen.py`:

`from radio_configuration import RadioConfiguration,\ 
RADIO_CONFIGURATIONS`

It should have been

`from flora_tools.radio_configuration import RadioConfiguration\
RADIO_CONFIGURATIONS`

The real deal here is why I was allowed to directly import from 
`radio_configuration` in the first place. I'm not allowed to directly import a 
submodule in the toy project without the proper root module name appended. 
Maybe I don't see the big picture, or have some crude options/monkey_patching 
enabled.

Nevertheless, the behaviour regarding Enum comparisons and different import 
paths seems to me quite misleading.

Best regards
Atokulus

--

___
Python tracker 
<https://bugs.python.org/issue30545>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30545] Enum equality across modules: comparing objects instead of values

2018-08-11 Thread Markus Wegmann


Markus Wegmann  added the comment:

Hi there!

I came as well in contact with this kind of bug. Sadly, I could not replicate 
it with a simplified toy example.

You can experience the bug, if checkout

https://github.com/Atokulus/flora_tools/tree/56bb17ea33c910915875214e916ab73f567b3b0c

and run

`python3.7 main.py generate_code -d ..`

You find the crucial part where the identity check fails at 'radio_math.py:102' 
in function `get_message_toa`. The program then fails, due to the wrong program 
flow.

`
C:\Users\marku\AppData\Local\Programs\Python\Python37\python.exe 
C:/Users/marku/PycharmProjects/flora_tools/flora_tools/__main__.py 
generate_code -d C:\Users\marku\Documents\flora
Traceback (most recent call last):
  File "C:/Users/marku/PycharmProjects/flora_tools/flora_tools/__main__.py", 
line 110, in 
main()
  File "C:/Users/marku/PycharmProjects/flora_tools/flora_tools/__main__.py", 
line 104, in main
generate_code(args.path)
  File "C:/Users/marku/PycharmProjects/flora_tools/flora_tools/__main__.py", 
line 58, in generate_code
code_gen = CodeGen(flora_path)
  File 
"C:\Users\marku\PycharmProjects\flora_tools\flora_tools\codegen\codegen.py", 
line 37, in __init__
self.generate_all()
  File 
"C:\Users\marku\PycharmProjects\flora_tools\flora_tools\codegen\codegen.py", 
line 40, in generate_all
self.generate_radio_constants()
  File 
"C:\Users\marku\PycharmProjects\flora_tools\flora_tools\codegen\codegen.py", 
line 72, in generate_radio_constants
radio_toas.append([math.get_message_toa(payload) for payload in payloads])
  File 
"C:\Users\marku\PycharmProjects\flora_tools\flora_tools\codegen\codegen.py", 
line 72, in 
radio_toas.append([math.get_message_toa(payload) for payload in payloads])
  File "C:\Users\marku\PycharmProjects\flora_tools\flora_tools\radio_math.py", 
line 130, in get_message_toa
) / self.configuration.bitrate
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Process finished with exit code 1
`

In the appendix, you find a toy project with similar structure, which in 
contrast to `flora_tools` works flawlessly.

I hope there is somebody out there with a little more experience in spotting 
the cause. If there is a bug in Python or CPython, it might have quite a 
security & safety impact.

Meanwhile I will hotfix my program by comparing the unerlying enum values.

Best regards
Atokulus

--
nosy: +Markus Wegmann
Added file: https://bugs.python.org/file47747/enum_bug-flawless_example.zip

___
Python tracker 
<https://bugs.python.org/issue30545>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com