Skip to content

Conversation

@jamadden
Copy link
Member

Fixes #91

Remove many (or most) now-redundant 'pragma: no cover'.

A few minor test changes to get full branch coverage.

Fixes #91

Remove many (or most) now-redundant 'pragma: no cover'.

A few minor test changes to get full branch coverage.
@jamadden jamadden requested review from icemac and tseaver June 14, 2017 21:58
# the coverage for this block there. :(
if PYTHON3: # pragma: no cover
raise TypeError('Class advice impossible in Python3')
assert not PYTHON3, "Class advice impossible in Python 3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't convert TypeError to AssertionError (we only raise them in test code).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale is that python -O suppresses assertions: we don't want to remove that check in that case.

Copy link
Member Author

@jamadden jamadden Jun 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a private implementation method for this module. Its callers already perform this same check and raise a TypeError before calling it. So the if/raise statement was dead code.

I could completely remove the assert?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, if you're sure. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure. Even if we take the assert out and manually try to use the implementation method, we get hit with another explicit TypeError:

Python 3.6.1 (default, Jun  1 2017, 07:41:42)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from zope.interface.declarations import _implements, classImplements
>>> from zope.interface import Interface
>>> class Foo(object):
...   _implements('implements', Interface, classImplements)
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in Foo
  File "//.tox/py36/lib/python3.6/site-packages/zope/interface/declarations.py", line 446, in _implements
    raise TypeError(name+" can be used only from a class definition.")
TypeError: implements can be used only from a class definition.


import sys
if sys.version[0] == '2': # This test only makes sense under Python 2.x
if sys.version_info[0] < 3: # This test only makes sense under Python 2.x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than testing sys.version_info, this is probably better as a conditional import:

        try:
            from types import ClassType
        except ImportError:
            pass
        else:
            assert not isinstance(C, (type, ClassType))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it probably is :) It started out as a copy of the doctest in odd.py, I just fixed this when I was globally fixing the same thing in other files.

…all its callers already do this guard; be more explicit about ClassType in test_odd_declarations
@jamadden jamadden merged commit 50a9193 into master Jun 14, 2017
@jamadden
Copy link
Member Author

Thank you!

I'm going to push 4.4.2 to PyPI now unless there are objections.

@jamadden jamadden deleted the combined-coverage branch June 14, 2017 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants