Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namedtuples? #37

Open
javadba opened this issue Sep 25, 2019 · 5 comments
Open

Namedtuples? #37

javadba opened this issue Sep 25, 2019 · 5 comments

Comments

@javadba
Copy link

javadba commented Sep 25, 2019

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_'

@BuvinJT
Copy link

BuvinJT commented Sep 25, 2019

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.

@BuvinJT
Copy link

BuvinJT commented Sep 25, 2019

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.

@javadba
Copy link
Author

javadba commented Sep 25, 2019

Thx for this info Buvin, i will try out your interim fixes by adding to the plain_names

@BuvinJT
Copy link

BuvinJT commented Sep 25, 2019

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") )

@BuvinJT
Copy link

BuvinJT commented Sep 25, 2019

You're welcome, @javadba. Checkout my last suggestion to. It may actually be better for Named Tuples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants