-
Notifications
You must be signed in to change notification settings - Fork 39
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
Implement hasattr_warn(); run to remove hasattr(prop) calls #362
Labels
Comments
trevorbaca
referenced
this issue
Mar 22, 2014
Consider the following code: measure = Measure((4, 4), "c'4") staff = Staff([measure]) score = Score([staff]) score_block = lilypondfiletools.Block(name='score') score_block.items.append(score) The above measure is underfull. Formatting it should result in an UnderfullContainerError. And in fact if we format the measure, the staff or the score we'll raise such an error. However, until this commit, formatting the score block would raise no error and would produce the following LilyPond syntax: \score { } Why is this? It's all due to Python's hasattr implementation. When formatting itself, Block calls hasattr on each item in its items array, testing if they have anything like `_get_format_pieces` or `_format_pieces` that it could use to construct some LilyPond syntax. Python's hasattr not only executes each attribute it tests for but also traps any exceptions raised in the process. And not only does it trap exceptions, but it also returns False if it *does* encounter an exception. All together this means that we never find out about our malformed measure, and our score block assumes that the score it contains has no LilyPond format, so nothing gets formatted either. This has been fixed by testing for the presence of `_format_pieces` in the dir() of each item in the block's item array, and now exceptions are raised again.
trevorbaca
referenced
this issue
Apr 8, 2015
NOTE: Be careful with hasattr(). This function consumes exceptions silently, returning false instead.
Still valid in June 2017. |
trevorbaca
changed the title
Implement hasattr_warn() and run over codebase to remove hasattr(prop) calls
Implement hasattr_warn(); run to remove hasattr(prop) calls
Jul 3, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 3, 2017
A Current doctests:
Current pytests:
|
Current doctests:
Current pytests:
|
trevorbaca
added a commit
that referenced
this issue
Jul 4, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 4, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 4, 2017
Done in 2.21. The following remains in the Abjad
|
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
trevorbaca
added a commit
that referenced
this issue
Jul 31, 2017
Added (commented-out) hasattr_warn() to Abjad __init__.py.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We've experienced too many relatively significant bugs related to calling
hasattr()
on properties.We need a way to audit the entire codebase and remove all cases of calling
hasattr()
on properties.How to do this?
We don't need anything superelegant. Just something that will let us run over the codebase and go manually fix everything found.
One solution would be to implement a custom
hasattr_warn()
function. The function would raise an exception in the case that it's input argument is a property. Probably define directly in theabjad/__init__.py
module so that we can then add the function to the__builtins__
namespace with something like__builtins__['hasattr_warn'] = hasattr_warn
. Then we could globally search and replace allhasattr()
withhasattr_warn()
and then run and fix the tests iteratively until everything runs and no more exceptions are raised. Then globally search and replace to change allhasattr_warn()
calls back to vanillahasattr()
.The text was updated successfully, but these errors were encountered: