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

Fixes #653 use deprecated_call as context_manager #1041

Closed

Conversation

chiller
Copy link
Contributor

@chiller chiller commented Sep 21, 2015

No description provided.

"""
if not func:
warnings.simplefilter('always')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the simplefilter happening outside of a context manager affects global state

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is moving warnings.simplefilter('always') inside WarningsChecker.__enter__ a solution?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it already does that, see the line before return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I've found that, currently am trying to figure out why it only works if append=True is unset:
WarningsRecorder.__enter__:warnings.simplefilter('always') - works fine
WarningsRecorder.__enter__:warnings.simplefilter('always', append=True) - the existing code, breaks my PR tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append decides whether the filter is inserted at the end or the beginning in the warnings filter list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I have not yet figured out why that would change the outcome of the deprecated_call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is because in a list of filters - the first one that matches will apply, and upon inspecting the filters (before the always is appended):

[('ignore', None, <type 'exceptions.DeprecationWarning'>, None, 0), 
('ignore', None, <type 'exceptions.PendingDeprecationWarning'>, None, 0),
 ('ignore', None, <type 'exceptions.ImportWarning'>, None, 0),
('ignore', None, <type 'exceptions.BytesWarning'>, None, 0)]

I see now why appending always will never work. The question is : is there a point in appending this filter in the first place(instead of prepending) since it is possible to have one that will match before it(being shadowed).

@RonnyPfannschmidt
Copy link
Member

@chiller i think we need a option to clear the errors list or to insert at the beginning for the recorder
if you are a pyconuk, perhaps talk with @flub

@chiller
Copy link
Contributor Author

chiller commented Sep 21, 2015

I am, will do

@chiller
Copy link
Contributor Author

chiller commented Sep 21, 2015

Discussed with @flub that it doesn't make sense to append the filter

@RonnyPfannschmidt
Copy link
Member

good investigative work

instead of merging master, please use a rebase and a force push so we can keep the main history less eratic

@chiller chiller force-pushed the 653-deprecated-context-manager branch from c3ce7a0 to 9f77a85 Compare September 21, 2015 18:05
@chiller
Copy link
Contributor Author

chiller commented Sep 21, 2015

ok, done

@hpk42
Copy link
Contributor

hpk42 commented Sep 22, 2015

please retarget to "features" branch -- "master" is since today meant for bugfixes only. sorry for the inconvenience.

@RonnyPfannschmidt
Copy link
Member

we can manually merge into feature

@chiller
Copy link
Contributor Author

chiller commented Sep 22, 2015

@RonnyPfannschmidt I didn't understand your comment, should I branch my code from feature instead and create a new PR? I am happy to do that. Is there maybe an easier way?

@RonnyPfannschmidt
Copy link
Member

@chiller i'll merge myself in a bit (github does not have an ui to make the same pull request against different branch without a mess)

@RonnyPfannschmidt
Copy link
Member

it was merged into the features branch

@chiller
Copy link
Contributor Author

chiller commented Sep 22, 2015

thanks

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 92.596% when pulling 9f77a85 on chiller:653-deprecated-context-manager into c30eafa on pytest-dev:master.

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.

4 participants