Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

fix GenericType operators #423

Closed
erickvermot opened this issue Jul 25, 2017 · 1 comment
Closed

fix GenericType operators #423

erickvermot opened this issue Jul 25, 2017 · 1 comment

Comments

@erickvermot
Copy link
Contributor

In current implementation, GenericType does not inherit from any other class, and for that reason has to implement its own operators methods, like __add__ etc...
The problem is that this leads to possible mistakes (like in the current definition of __lt__ - see bellow), and also forbid GenericType s from being used with operators that are not included in the definition (like with __int__, or __mod__).
A much simpler solution is to make it inherit from python primitive types, as proposed here: #198 (comment) .

current problems:

>>> a = GenericType(2)
>>> a > a
True

>>> int(a)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'GenericType'

>>> a // 2
TypeError: unsupported operand type(s) for //: 'GenericType' and 'int'
@cemsbr
Copy link
Contributor

cemsbr commented Aug 3, 2017

The first is fixed:

>>> from pyof.foundation.base import GenericType
>>> a = GenericType(2)
>>> a > a
False

int(a) and a // 2 don't make sense for children like DPID, for example.

@cemsbr cemsbr closed this as completed Aug 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants