Opy
Opy copied to clipboard
Namedtuples?
When trying to use a namedtuple the attributes are not matching up:
Original:
Arg = ntup('Arg','name nix gnu help default action',defaults=(None,)*6)
for arg in args:
parser.add_argument(arg.nix, arg.gnu, action='store', help=arg.help, default=arg.default)
Obfsucated:
l1l111l_opy_ = namedtuple(l1ll1ll_opy_ (u"ࠫࡆࡸࡧࠨࡩ"),l1ll1ll_opy_ (u"ࠬࡴࡡࡧࠣࡲࡾࠠࡨࡰࡸࠤࡱࠢࡧࡩࡧࡵࡶࠣࡥࡨࡺࡩࡰࡰࠪࡪ"),defaults=(None,)*6)
for arg in args:
parser.add_argument(arg.l11111l_opy_, arg.l1llll1l1_opy_, action=l1ll1ll_opy_ (u"ࠧࡴࡶࡲࡶࡪ࠭ࡺ"), help=arg.help, default=arg.default)
Result:
AttributeError: 'Arg' object has no attribute 'l11111l_opy_'
Yes, this is another "face" to a major known bug. It is directly related to a couple of other such things. Check out my fork at: https://github.com/BuvinJT/Opy
If you dig deep into my readme, you'll see a list of bugs I've documented and the workarounds for them. This issue is right at the top of the list for problems. Refer to these very similar issues:
MAJOR) Bug: Function calls cannot use keyword arguments. The argument keys/names become obfuscated by the caller, yet there is no resolution in the function definition.
Workaround: A) Use positional arguments B) Append the argument keywords to the plain_names list.
(MAJOR) Bug: String obfuscation of dictionary keys may break using calling functions in external modules and for external resources where such must be defined in clear text.
Workaround: Define the dictionaries and/or key constants in a dedicated module (for import where needed), which is then added to the plain_files list.
I'm developing Opy further as a component within a large project. https://github.com/BuvinJT/distbuilder
I plan to spend a while hammering on this library until all the kinks are worked out. I'm perhaps a month out from getting into that, and then it might another one or two before I've "perfected" it to my liking. You can certainly check back in on my projects periodically to see when I get around to patching this issue.
Thx for this info Buvin, i will try out your interim fixes by adding to the plain_names
Actually, this excerpt from my readme might help you get over the hump help with your named tuples problem:
(UNRESOLVABLE?) Bug: Dynamically created object attributes cannot be referenced directly.
Example: The popular argparse module creates attributes "magically" e.g. shoen below with "foo".
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--foo', help='foo help')
args = parser.parse_args()
print( args.foo )
Opy will obfuscate the '--foo' string and the .foo attribute without binding them.
Workaround:
A) Convert args to a dictionary
args = vars(parser.parse_args())
or
args = parser.parse_args().__dict__
Then, access the value via the the key:
print( args["foo"] )
print( args.get("foo") )
B) Access the "magic" attribute via getattr
print( getattr(args,"foo") )
You're welcome, @javadba. Checkout my last suggestion to. It may actually be better for Named Tuples.