Skip to content

no-op for un-evaluatable items in globals #25

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

Closed
wants to merge 1 commit into from

Conversation

AlanCoding
Copy link

This pull request carries out what was suggested in the email:

https://mail.python.org/pipermail/python-ldap/2016q3/003789.html

The project that I am working on has had to keep the version of pytest pinned ever since encountering the problem mentioned here, because pytest puts decorators in the pattern of @something as a key that shows up inside of dir(). A major takeaway is that you should not count on keys inside of dir() to be something that can be evaluated in all environments.

https://github.com/ansible/awx/blob/devel/requirements/requirements_dev.txt#L8

If you could make this change, no existing workflow should be affected, and we will be able to upgrade pytest as soon as a new release of pytest-ldap is cut.

My alternative solution is that this diff would also suffice:

 SCHEMA_ATTR_MAPPING = {}
 
 for _name in dir():
-  o = eval(_name)
+  o = globals()[_name]
   if hasattr(o,'schema_attribute'):
     SCHEMA_CLASS_MAPPING[o.schema_attribute] = o
     SCHEMA_ATTR_MAPPING[o] = o.schema_attribute

By the way, thank you for taking over management of this project. No one responded to my email, but I am delighted to be able to make the pull request directly now.

This is for compatibility with other libraries that inject
extra variables, like unit testing with pytest.
@codecov
Copy link

codecov bot commented Nov 27, 2017

Codecov Report

Merging #25 into master will decrease coverage by 0.01%.
The diff coverage is 50%.

@@            Coverage Diff             @@
##           master      #25      +/-   ##
==========================================
- Coverage   62.35%   62.33%   -0.02%     
==========================================
  Files          45       45              
  Lines        4362     4365       +3     
  Branches      735      735              
==========================================
+ Hits         2720     2721       +1     
- Misses       1335     1337       +2     
  Partials      307      307
Impacted Files Coverage Δ
Lib/ldap/schema/subentry.py 54.61% <50%> (-0.24%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2b7faf...2c3063f. Read the comment docs.

@tiran
Copy link
Member

tiran commented Nov 27, 2017

Oh yes, that's a peculiar way to access a variable. How about for _name, _value in vars().items() instead? We should eventually replace the code with a registry of schema classes.

encukou added a commit to encukou/python-ldap that referenced this pull request Nov 27, 2017
This is for compatibility with other libraries that inject
extra variables, like unit testing with pytest.

Based on a suggestion by AlanCoding:
python-ldap#25
@encukou
Copy link
Member

encukou commented Nov 27, 2017

I'd use list(vars().values()) – the globals are mutated, and the name is not needed.

Filed as a PR: #35

@encukou encukou closed this in #35 Nov 27, 2017
@encukou
Copy link
Member

encukou commented Nov 27, 2017

Thanks for the PR!

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

Successfully merging this pull request may close these issues.

3 participants