How to properly check if a variable is PolyLike? #496
-
Hello, How can we check if a variable is First I tried to wrap my code with a try statement. import galois
try:
poly = galois.Poly(provided_poly_like)
except ValueError, TypeError:
pass But this fails if >>> galois.Poly(galois.conway_poly(2, 12))
TypeError: Argument 'coeffs' must be an instance of (<class 'list'>, <class 'tuple'>, <class 'numpy.ndarray'>, <class 'galois.Array'>), not <class 'galois.Poly'>. So later I tried using assert isinstance(provided_poly_like, galois.typing.PolyLike.__args__) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I have a private constructor that converts What are you thoughts? Is this what you're looking for? By the way, the type checking if very rudimentary. I've been looking for an easier way to runtime type check using type annotations, but every solution I've found has been shoddy. galois/src/galois/_polys/_poly.py Lines 130 to 149 in a140a46 |
Beta Was this translation helpful? Give feedback.
I have a private constructor that converts
PolyLike
intoPoly
. I found it useful in the internal library code. At one point I considered making it a public constructor. I also toyed with the idea of makinggalois.Poly()
acceptPolyLike
.What are you thoughts? Is this what you're looking for? By the way, the type checking if very rudimentary. I've been looking for an easier way to runtime type check using type annotations, but every solution I've found has been shoddy.
galois/src/galois/_polys/_poly.py
Lines 130 to 149 in a140a46