Discussion:
[PEAK] Default value lost in binding.Obtain()
Alexey Smishlayev
2015-09-29 13:03:26 UTC
Permalink
Hello!

Today, fiddling with the binding.Obtain() I noticed that the default
value gets lost.

In my application, I have a component tree and I want an attribute to be
None)
So, in case that no component defines a callbackFunction, the lambda
function would be used as a fallback.
Unfortunately, "default" option is ignored unless target name contains
slashes (e.g. "/callbackFunction", "./callBackFunction",
"../callbackFunction")

I went to the peak/binding/components.py trying to fix it and propose
the attached patch.
The problem is that default value was not propagated to the
acquireComponent() call, so an exception occurred.


Best regards,
Alexey Smishlayev
PJ Eby
2015-09-29 22:53:07 UTC
Permalink
Thanks for reporting the problem. Unfortunately your patch will mask
any other sort of name error, including one that happens indirectly as
a side effect of the lookup. I think the correct fix is going to be
to change the nameNotFound() method of config.IConfigurationRoot to
include a default (defaulting to NOT_GIVEN), and have
acquireComponent() take a default and pass it along to nameNotFound().
This would handle the case of a direct lookup failing by returning the
default, but still raise an error for any other part of the process
getting a naming error.
Post by Alexey Smishlayev
Hello!
Today, fiddling with the binding.Obtain() I noticed that the default value
gets lost.
In my application, I have a component tree and I want an attribute to be
None)
So, in case that no component defines a callbackFunction, the lambda
function would be used as a fallback.
Unfortunately, "default" option is ignored unless target name contains
slashes (e.g. "/callbackFunction", "./callBackFunction",
"../callbackFunction")
I went to the peak/binding/components.py trying to fix it and propose the
attached patch.
The problem is that default value was not propagated to the
acquireComponent() call, so an exception occurred.
Best regards,
Alexey Smishlayev
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
Alexey Smishlayev
2015-10-01 09:19:49 UTC
Permalink
Okay, that's probably going to be better. Anyways, I'm going to apply
the patch locally for now. Is there hope for a new snapshot with the fix?


Regards,
Alexey Smishlayev
Post by PJ Eby
Thanks for reporting the problem. Unfortunately your patch will mask
any other sort of name error, including one that happens indirectly as
a side effect of the lookup. I think the correct fix is going to be
to change the nameNotFound() method of config.IConfigurationRoot to
include a default (defaulting to NOT_GIVEN), and have
acquireComponent() take a default and pass it along to nameNotFound().
This would handle the case of a direct lookup failing by returning the
default, but still raise an error for any other part of the process
getting a naming error.
Post by Alexey Smishlayev
Hello!
Today, fiddling with the binding.Obtain() I noticed that the default value
gets lost.
In my application, I have a component tree and I want an attribute to be
None)
So, in case that no component defines a callbackFunction, the lambda
function would be used as a fallback.
Unfortunately, "default" option is ignored unless target name contains
slashes (e.g. "/callbackFunction", "./callBackFunction",
"../callbackFunction")
I went to the peak/binding/components.py trying to fix it and propose the
attached patch.
The problem is that default value was not propagated to the
acquireComponent() call, so an exception occurred.
Best regards,
Alexey Smishlayev
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
Alexey Smishlayev
2015-10-28 12:45:31 UTC
Permalink
Hi!
How can I get an svn checkout to incorporate described changes and
propose another patch? This is essential for our software and I'd like
to see it merged in upstream as soon as possible.

Best regards,
Alexey
Post by PJ Eby
Thanks for reporting the problem. Unfortunately your patch will mask
any other sort of name error, including one that happens indirectly as
a side effect of the lookup. I think the correct fix is going to be
to change the nameNotFound() method of config.IConfigurationRoot to
include a default (defaulting to NOT_GIVEN), and have
acquireComponent() take a default and pass it along to nameNotFound().
This would handle the case of a direct lookup failing by returning the
default, but still raise an error for any other part of the process
getting a naming error.
Post by Alexey Smishlayev
Hello!
Today, fiddling with the binding.Obtain() I noticed that the default value
gets lost.
In my application, I have a component tree and I want an attribute to be
None)
So, in case that no component defines a callbackFunction, the lambda
function would be used as a fallback.
Unfortunately, "default" option is ignored unless target name contains
slashes (e.g. "/callbackFunction", "./callBackFunction",
"../callbackFunction")
I went to the peak/binding/components.py trying to fix it and propose the
attached patch.
The problem is that default value was not propagated to the
acquireComponent() call, so an exception occurred.
Best regards,
Alexey Smishlayev
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
PJ Eby
2015-10-30 18:59:31 UTC
Permalink
Does this patch work for you?
Hi!
How can I get an svn checkout to incorporate described changes and propose
another patch? This is essential for our software and I'd like to see it
merged in upstream as soon as possible.
Best regards,
Alexey
Post by PJ Eby
Thanks for reporting the problem. Unfortunately your patch will mask
any other sort of name error, including one that happens indirectly as
a side effect of the lookup. I think the correct fix is going to be
to change the nameNotFound() method of config.IConfigurationRoot to
include a default (defaulting to NOT_GIVEN), and have
acquireComponent() take a default and pass it along to nameNotFound().
This would handle the case of a direct lookup failing by returning the
default, but still raise an error for any other part of the process
getting a naming error.
Post by Alexey Smishlayev
Hello!
Today, fiddling with the binding.Obtain() I noticed that the default value
gets lost.
In my application, I have a component tree and I want an attribute to be
None)
So, in case that no component defines a callbackFunction, the lambda
function would be used as a fallback.
Unfortunately, "default" option is ignored unless target name contains
slashes (e.g. "/callbackFunction", "./callBackFunction",
"../callbackFunction")
I went to the peak/binding/components.py trying to fix it and propose the
attached patch.
The problem is that default value was not propagated to the
acquireComponent() call, so an exception occurred.
Best regards,
Alexey Smishlayev
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
Alexey Smishlayev
2015-10-31 07:09:23 UTC
Permalink
It does except for a little typo, at line 60 of the patch it should read
"ob = acquireComponent(component, attr, default)", then it works good.
Thank you!


Best regards,
Alexey
Post by PJ Eby
Does this patch work for you?
Hi!
How can I get an svn checkout to incorporate described changes and propose
another patch? This is essential for our software and I'd like to see it
merged in upstream as soon as possible.
Best regards,
Alexey
Post by PJ Eby
Thanks for reporting the problem. Unfortunately your patch will mask
any other sort of name error, including one that happens indirectly as
a side effect of the lookup. I think the correct fix is going to be
to change the nameNotFound() method of config.IConfigurationRoot to
include a default (defaulting to NOT_GIVEN), and have
acquireComponent() take a default and pass it along to nameNotFound().
This would handle the case of a direct lookup failing by returning the
default, but still raise an error for any other part of the process
getting a naming error.
Post by Alexey Smishlayev
Hello!
Today, fiddling with the binding.Obtain() I noticed that the default value
gets lost.
In my application, I have a component tree and I want an attribute to be
None)
So, in case that no component defines a callbackFunction, the lambda
function would be used as a fallback.
Unfortunately, "default" option is ignored unless target name contains
slashes (e.g. "/callbackFunction", "./callBackFunction",
"../callbackFunction")
I went to the peak/binding/components.py trying to fix it and propose the
attached patch.
The problem is that default value was not propagated to the
acquireComponent() call, so an exception occurred.
Best regards,
Alexey Smishlayev
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
PJ Eby
2015-10-31 14:49:35 UTC
Permalink
That's not a typo. It's part of a strategy to work with multi-part
names. If the name is a path like 'foo/bar' and acquiring 'foo'
fails, you should not end up with the 'bar' attribute of your default,
which is what would happen with your version. My version still has a
bug, in that it doesn't work right with *single*-part names, because
the for-loop doesn't execute in that case. This code really needs
proper tests, but there were apparently never any real tests for this
functionality in the first place. Most of PEAK's early code was
developed before "test first" and "test-driven" were my standard
practice. :-(

Anyway, here's a new version that should fix both issues. I will have
to see about adding some proper tests for this thing and back-testing
to make sure they fail without the patch.
It does except for a little typo, at line 60 of the patch it should read "ob
= acquireComponent(component, attr, default)", then it works good. Thank
you!
Best regards,
Alexey
Post by PJ Eby
Does this patch work for you?
Hi!
How can I get an svn checkout to incorporate described changes and propose
another patch? This is essential for our software and I'd like to see it
merged in upstream as soon as possible.
Best regards,
Alexey
Post by PJ Eby
Thanks for reporting the problem. Unfortunately your patch will mask
any other sort of name error, including one that happens indirectly as
a side effect of the lookup. I think the correct fix is going to be
to change the nameNotFound() method of config.IConfigurationRoot to
include a default (defaulting to NOT_GIVEN), and have
acquireComponent() take a default and pass it along to nameNotFound().
This would handle the case of a direct lookup failing by returning the
default, but still raise an error for any other part of the process
getting a naming error.
Post by Alexey Smishlayev
Hello!
Today, fiddling with the binding.Obtain() I noticed that the default value
gets lost.
In my application, I have a component tree and I want an attribute to be
None)
So, in case that no component defines a callbackFunction, the lambda
function would be used as a fallback.
Unfortunately, "default" option is ignored unless target name contains
slashes (e.g. "/callbackFunction", "./callBackFunction",
"../callbackFunction")
I went to the peak/binding/components.py trying to fix it and propose the
attached patch.
The problem is that default value was not propagated to the
acquireComponent() call, so an exception occurred.
Best regards,
Alexey Smishlayev
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
Alexey Smishlayev
2015-10-31 19:02:20 UTC
Permalink
Sorry, I suppose I didn't see the big picture. Anyways, this one works
as good. I can confirm that in my case (onSubprocessConnected =
binding.Obtain("onSubprocessConnected", default=lambda connection: None)
it didn't work before the patch (I define onSubprocessConnected in
another class up the hierarchy tree).

Thank you for the help! I hope it goes well with the tests.


Best regards,
Alexey
Post by PJ Eby
That's not a typo. It's part of a strategy to work with multi-part
names. If the name is a path like 'foo/bar' and acquiring 'foo'
fails, you should not end up with the 'bar' attribute of your default,
which is what would happen with your version. My version still has a
bug, in that it doesn't work right with *single*-part names, because
the for-loop doesn't execute in that case. This code really needs
proper tests, but there were apparently never any real tests for this
functionality in the first place. Most of PEAK's early code was
developed before "test first" and "test-driven" were my standard
practice. :-(
Anyway, here's a new version that should fix both issues. I will have
to see about adding some proper tests for this thing and back-testing
to make sure they fail without the patch.
It does except for a little typo, at line 60 of the patch it should read "ob
= acquireComponent(component, attr, default)", then it works good. Thank
you!
Best regards,
Alexey
Post by PJ Eby
Does this patch work for you?
Hi!
How can I get an svn checkout to incorporate described changes and propose
another patch? This is essential for our software and I'd like to see it
merged in upstream as soon as possible.
Best regards,
Alexey
Post by PJ Eby
Thanks for reporting the problem. Unfortunately your patch will mask
any other sort of name error, including one that happens indirectly as
a side effect of the lookup. I think the correct fix is going to be
to change the nameNotFound() method of config.IConfigurationRoot to
include a default (defaulting to NOT_GIVEN), and have
acquireComponent() take a default and pass it along to nameNotFound().
This would handle the case of a direct lookup failing by returning the
default, but still raise an error for any other part of the process
getting a naming error.
Post by Alexey Smishlayev
Hello!
Today, fiddling with the binding.Obtain() I noticed that the default value
gets lost.
In my application, I have a component tree and I want an attribute to be
None)
So, in case that no component defines a callbackFunction, the lambda
function would be used as a fallback.
Unfortunately, "default" option is ignored unless target name contains
slashes (e.g. "/callbackFunction", "./callBackFunction",
"../callbackFunction")
I went to the peak/binding/components.py trying to fix it and propose the
attached patch.
The problem is that default value was not propagated to the
acquireComponent() call, so an exception occurred.
Best regards,
Alexey Smishlayev
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
PJ Eby
2015-11-01 00:49:28 UTC
Permalink
It's done now, with tests, in Subversion. Let me know if you have any
more trouble with this.
Sorry, I suppose I didn't see the big picture. Anyways, this one works as
good. I can confirm that in my case (onSubprocessConnected =
binding.Obtain("onSubprocessConnected", default=lambda connection: None) it
didn't work before the patch (I define onSubprocessConnected in another
class up the hierarchy tree).
Thank you for the help! I hope it goes well with the tests.
Best regards,
Alexey
That's not a typo. It's part of a strategy to work with multi-part
names. If the name is a path like 'foo/bar' and acquiring 'foo'
fails, you should not end up with the 'bar' attribute of your default,
which is what would happen with your version. My version still has a
bug, in that it doesn't work right with *single*-part names, because
the for-loop doesn't execute in that case. This code really needs
proper tests, but there were apparently never any real tests for this
functionality in the first place. Most of PEAK's early code was
developed before "test first" and "test-driven" were my standard
practice. :-(
Anyway, here's a new version that should fix both issues. I will have
to see about adding some proper tests for this thing and back-testing
to make sure they fail without the patch.
It does except for a little typo, at line 60 of the patch it should read "ob
= acquireComponent(component, attr, default)", then it works good. Thank
you!
Best regards,
Alexey
Does this patch work for you?
Hi!
How can I get an svn checkout to incorporate described changes and propose
another patch? This is essential for our software and I'd like to see it
merged in upstream as soon as possible.
Best regards,
Alexey
Thanks for reporting the problem. Unfortunately your patch will mask
any other sort of name error, including one that happens indirectly as
a side effect of the lookup. I think the correct fix is going to be
to change the nameNotFound() method of config.IConfigurationRoot to
include a default (defaulting to NOT_GIVEN), and have
acquireComponent() take a default and pass it along to nameNotFound().
This would handle the case of a direct lookup failing by returning the
default, but still raise an error for any other part of the process
getting a naming error.
Hello!
Today, fiddling with the binding.Obtain() I noticed that the default value
gets lost.
In my application, I have a component tree and I want an attribute to be
None)
So, in case that no component defines a callbackFunction, the lambda
function would be used as a fallback.
Unfortunately, "default" option is ignored unless target name contains
slashes (e.g. "/callbackFunction", "./callBackFunction",
"../callbackFunction")
I went to the peak/binding/components.py trying to fix it and propose the
attached patch.
The problem is that default value was not propagated to the
acquireComponent() call, so an exception occurred.
Best regards,
Alexey Smishlayev
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
_______________________________________________
PEAK mailing list
http://www.eby-sarna.com/mailman/listinfo/peak
Continue reading on narkive:
Loading...