Pros:
- adds another level of indirection, makes the environment more dynamic
- in particular, allows to avoid more code duplication
Cons:
- not applicable for function namespaces (due to optimization)
- adds another level of indirection, makes the environment more dynamic
- "lexical references" are much harder to track and maintain
- if created names are arbitrary, conflicts are waiting to happen
- it's hard to find the ins and outs in the code base and predict its behaviour
- that's why these tricks may upset code checking tools like
pylint
- if variables are processed in a similar way, they probably belong together separately from others (in a dedicated
dict
) rather than reusing a namespace dict, making it a mess in the process
In brief, at the abstraction level Python's language and runtime features are designed for, it's only good in small, well-defined amounts.