codecian February 2016

what does "unqualified on right hand side" mean in OOPs (Python)?

I came across "unqualified on right hand side" phrase while reading oops concept in python for usage like self._customer = customer. What that phrase trying to explain? Complete statement is

For example, the command, self._customer = customer, assigns the instance variable self._customer to the parameter customer; note that because customer is unqualified on the right-hand side, it refers to the parameter in the local namespace. --Data Structures and Algorithms in Python p. 72

Answers


kdopen February 2016

According to the Python docs

qualified name

A dotted name showing the “path” from a module’s global scope to a class, function or method defined in that module, as defined in PEP 3155. For top-level functions and classes, the qualified name is the same as the object’s name:

...

When used to refer to modules, the fully qualified name means the entire dotted path to the module, including any parent packages, e.g. email.mime.text:

Put more simply, qualifying a name in Python means that you explicitly define its scope. Thus self._customer is a qualified name (it identifies the instance variable customer for the enclosing class) whereas the bare customerreference does not specify any scope qualifications.

When a name is unqualified, Python applies Lexical Scoping rules to try and find the variable, searching (in order)

  • Local variables (including function parameters)
  • Variables local to any outer functions, if we're dealing with a nested function definition
  • Global variables
  • Built-in variables

Post Status

Asked in February 2016
Viewed 3,102 times
Voted 14
Answered 1 times

Search




Leave an answer