-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Replace isinstance call in Pipeline with structural checks #16726
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess this deserves a else now that raises that it won't work. Before, we were appended the policy and praying and it would have failed at the first "pipeline.run". Now, it silently drops the object passed as policy (silent drops are dangerous)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that's reasonable. Breaks a few (hacky) tests for Key Vault (fixed by #16784), we'll see what else. Pipeline still needs to silently ignore None in policy lists because Configuration uses that as a default value for policies; I added test coverage of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have this in policies/_base.py to make it live with SansIOHTTPPolicy definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, have done.
6f5ba7b to
fd9e436
Compare
|
Closing this because it's no longer blocking anything. |
Today, Pipeline calls
isinstance(policy, SansIOHTTPPolicy)to decide whether to wrap a policy with a runner definingsend(). Explicit type checking is contrary to our guidelines' preference for structural subtyping and it may also be useful to allow a SansIOHTTPPolicy to define its ownsend(). So, this PR replaces theisinstancecall with structural checks: if a policy implementssend(), Pipeline calls that method; otherwise, if a policy implements SansIOHTTPPolicy's methods, Pipeline wraps that policy with a runner. If an alleged policy doesn't define any of these methods, e.g. it'sNone, Pipeline ignores it.