Skip to content

Fix for issue #524 #527

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

Merged
merged 20 commits into from
Jan 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions python2/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import collections
import contextlib
import os
import pickle
import re
import subprocess
import sys
from unittest import TestCase, main, SkipTest
from copy import copy, deepcopy
Expand Down Expand Up @@ -1896,6 +1898,16 @@ def foo(x):

self.assertIsNone(typing.get_type_hints(foo))

def test_typing_compiles_with_opt(self):
file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'typing.py')
try:
subprocess.check_output('python -OO {}'.format(file_path),
stderr=subprocess.STDOUT,
shell=True)
except subprocess.CalledProcessError:
self.fail('Module does not compile with optimize=2 (-OO flag).')


if __name__ == '__main__':
main()
12 changes: 12 additions & 0 deletions src/test_typing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import contextlib
import collections
import os
import pickle
import re
import subprocess
import sys
from unittest import TestCase, main, skipUnless, SkipTest, expectedFailure
from copy import copy, deepcopy
Expand Down Expand Up @@ -2572,6 +2574,16 @@ def test_all(self):
self.assertIn('SupportsBytes', a)
self.assertIn('SupportsComplex', a)

def test_typing_compiles_with_opt(self):
file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'typing.py')
try:
subprocess.check_output('python -OO {}'.format(file_path),
stderr=subprocess.STDOUT,
shell=True)
except subprocess.CalledProcessError:
self.fail('Module does not compile with optimize=2 (-OO flag).')


if __name__ == '__main__':
main()
11 changes: 11 additions & 0 deletions typing_extensions/src_py2/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import contextlib
import collections
import pickle
import subprocess
from unittest import TestCase, main, skipUnless

from typing_extensions import NoReturn, ClassVar
Expand Down Expand Up @@ -740,6 +741,16 @@ def test_typing_extensions_defers_when_possible(self):
getattr(typing_extensions, item),
getattr(typing, item))

def test_typing_extensions_compiles_with_opt(self):
file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'typing_extensions.py')
try:
subprocess.check_output('python -OO {}'.format(file_path),
stderr=subprocess.STDOUT,
shell=True)
except subprocess.CalledProcessError:
self.fail('Module does not compile with optimize=2 (-OO flag).')


if __name__ == '__main__':
main()
12 changes: 12 additions & 0 deletions typing_extensions/src_py3/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import contextlib
import collections
import pickle
import subprocess
from unittest import TestCase, main, skipUnless
from typing import TypeVar, Optional
from typing import T, KT, VT # Not in __all__.
Expand Down Expand Up @@ -1208,6 +1209,7 @@ class E:


class AllTests(BaseTestCase):

def test_typing_extensions_includes_standard(self):
a = typing_extensions.__all__
self.assertIn('ClassVar', a)
Expand Down Expand Up @@ -1244,6 +1246,16 @@ def test_typing_extensions_defers_when_possible(self):
getattr(typing_extensions, item),
getattr(typing, item))

def test_typing_extensions_compiles_with_opt(self):
file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'typing_extensions.py')
try:
subprocess.check_output('python -OO {}'.format(file_path),
stderr=subprocess.STDOUT,
shell=True)
except subprocess.CalledProcessError:
self.fail('Module does not compile with optimize=2 (-OO flag).')


if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions typing_extensions/src_py3/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,9 @@ def __new__(cls, *args, **kwds):
if OLD_GENERICS:
return _generic_new(_next_in_mro(cls), cls, *args, **kwds)
return _generic_new(cls.__next_in_mro__, cls, *args, **kwds)

Protocol.__doc__ = Protocol.__doc__.format(bases="Protocol, Generic[T]" if
OLD_GENERICS else "Protocol[T]")
if Protocol.__doc__ is not None:
Protocol.__doc__ = Protocol.__doc__.format(bases="Protocol, Generic[T]" if
OLD_GENERICS else "Protocol[T]")

def runtime(cls):
"""Mark a protocol class as a runtime protocol, so that it
Expand Down