On 04/06/2015 12:19 PM, Peter Robinson wrote:
On Thu, Apr 2, 2015 at 4:31 PM, Pavol Babincak
<pbabinca(a)redhat.com> wrote:
> Python raised problem with local variable before:
>
> UnboundLocalError: local variable 'alias' referenced before
> assignment
> ---
> koji/plugin.py | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/koji/plugin.py b/koji/plugin.py
> index 1b83365..e189d1f 100644
> --- a/koji/plugin.py
> +++ b/koji/plugin.py
> @@ -118,12 +118,12 @@ def export_in(module, alias=None):
> """
> def dec(f):
> if alias is None:
Shouldn't the above alias now be local_alias too if the rest are being renamed?
No, that's referencing the (outer) function arg.
Scoped variables are somewhat limited in python. You can access a
variable from an outer scope, but if you assign to it, it is implicitly
made local to the function (breaking the scoping). You can declare a
variable global and then assign to it, but there is no similar
declaration for scoped variables.
This is why we don't need the same fix in the function above this one
(export_as). That one doesn't attempt to assign to the alias variable.
> - alias = "%s.%s" % (module, f.__name__)
> + local_alias = "%s.%s" % (module, f.__name__)
> else:
> - alias = "%s.%s" % (module, alias)
> + local_alias = "%s.%s" % (module, alias)
> setattr(f, 'exported', True)
> setattr(f, 'export_module', module)
> - setattr(f, 'export_alias', alias)
> + setattr(f, 'export_alias', local_alias)
> return f
> return dec
>
> --
> 1.9.3
>
> --
> buildsys mailing list
> buildsys(a)lists.fedoraproject.org
>
https://admin.fedoraproject.org/mailman/listinfo/buildsys