[myhdl-list] Re: VCD viewer ?
Brought to you by:
jandecaluwe
From: Jan D. <ja...@ja...> - 2005-04-25 12:34:45
|
Jean Demartini wrote: > I'm a little newbie in Python and some Python idiom's are a little > puzzling. Then my question: > > Why an enum variable is not a true class testable by isinstance(..,Enum) > ? this will simplify the catching of enum variables in _Signal.py. > > Jean I see your point, and I agree. Probably the "idiom" that puzzles you is the usage of the "nested" classes EnumItem and Enum in function enum in module _enum.py. This looks rather strange: my intention was to make sure these auxiliary classes are not directly usable by a user. But there are other ways to achieve that, such as giving them a "private" name, starting with underscore. You are correct in stating that these objects should be indentifiable by an instance check. This can be achieved easily by using a "dummy" parent class, whose sole purpose is to be subclassable by the actual (private) Enum class. This can be done as follows (untested): In _enum.py, create a new EnumType class at the module level: class EnumType(object): pass Subclass the private Enum class from EnumType instead of object: class Enum(EnumType): .... Make the EnumType class visible in __init__.py: from _enum import EnumType Now you can use it with: from myhdl import EnumType and things like isinstance(obj, EnumType) should work. Regards, Jan -- Jan Decaluwe - Resources bvba - http://jandecaluwe.com Losbergenlaan 16, B-3010 Leuven, Belgium Using Python as a hardware description language: http://jandecaluwe.com/Tools/MyHDL/Overview.html |