This repository has been archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from herczy/f/mobprogramming
Partially implement some typing types
- Loading branch information
Showing
6 changed files
with
242 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
Feature: typing types are supported in annotations | ||
|
||
As a developer | ||
In order to write PEP-484 compliant code | ||
I want to use the typing module | ||
|
||
Scenario: calling a function expecting a typing.Callable argument passes with callable argument | ||
Given that "mylib.py" contains the following code: | ||
""" | ||
import typing | ||
def apply_func(func: typing.Callable, *args): | ||
return func(*args) | ||
""" | ||
And that "myapp.py" contains the following type checked code: | ||
""" | ||
import mylib | ||
mylib.apply_func(lambda a, b: (b, a), 1, 2) | ||
""" | ||
When "python3 myapp.py" is run | ||
Then it must pass | ||
|
||
Scenario: calling a function expecting a typing.Callable argument fails with non-callable argument | ||
Given that "mylib.py" contains the following code: | ||
""" | ||
import typing | ||
def apply_func(func: typing.Callable, *args): | ||
return func(*args) | ||
""" | ||
And that "myapp.py" contains the following type checked code: | ||
""" | ||
import mylib | ||
mylib.apply_func(None, 1, 2, 3) | ||
""" | ||
When "python3 myapp.py" is run | ||
Then it must fail | ||
""" | ||
TypesafetyError: Argument 'func' of function 'apply_func' is invalid (expected: Callable; got: NoneType) | ||
""" | ||
|
||
Scenario: calling a function expecting a typing.Union argument passes | ||
Given that "mylib.py" contains the following type checked code: | ||
""" | ||
import typing | ||
def func(arg: typing.Union[int, str]): | ||
return arg | ||
""" | ||
And that "myapp.py" contains the following code: | ||
""" | ||
import mylib | ||
mylib.func(42) | ||
mylib.func("42") | ||
""" | ||
When "python3 myapp.py" is run | ||
Then it must pass | ||
|
||
Scenario: calling a function expecting a typing.Union argument fails with wrong argument | ||
Given that "mylib.py" contains the following code: | ||
""" | ||
import typing | ||
def func(arg: typing.Union[int, str]): | ||
return arg | ||
""" | ||
And that "myapp.py" contains the following type checked code: | ||
""" | ||
import mylib | ||
mylib.func(None) | ||
""" | ||
When "python3 myapp.py" is run | ||
Then it must fail | ||
""" | ||
TypesafetyError: Argument 'arg' of function 'func' is invalid (expected: typing.Union[int, str]; got: NoneType) | ||
""" | ||
|
||
Scenario: calling a function expecting a typing.Optional argument passes | ||
Given that "mylib.py" contains the following code: | ||
""" | ||
import typing | ||
def func(arg: typing.Optional[bool]): | ||
return arg | ||
""" | ||
And that "myapp.py" contains the following type checked code: | ||
""" | ||
import mylib | ||
mylib.func(False) | ||
mylib.func(None) | ||
""" | ||
When "python3 myapp.py" is run | ||
Then it must pass | ||
|
||
Scenario: calling a function expecting a typing.Optional argument fails with wrong argument | ||
Given that "mylib.py" contains the following code: | ||
""" | ||
import typing | ||
def func(arg: typing.Optional[float]): | ||
return arg | ||
""" | ||
And that "myapp.py" contains the following type checked code: | ||
""" | ||
import mylib | ||
mylib.func('spam') | ||
""" | ||
When "python3 myapp.py" is run | ||
Then it must fail | ||
""" | ||
TypesafetyError: Argument 'arg' of function 'func' is invalid (expected: typing.Union[float, NoneType]; got: str) | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,6 @@ | |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
# | ||
|
||
|
||
import sys | ||
if sys.hexversion < 0x03020000: | ||
raise RuntimeError("Required python version: 3.2 or newer (current: %s)" % sys.version) | ||
|
||
try: | ||
from setuptools import setup | ||
|
||
|
@@ -38,7 +33,7 @@ | |
are valid. | ||
""", | ||
license="LGPLv2+", | ||
version="2.0.0", | ||
version="2.1.0", | ||
author="Viktor Hercinger", | ||
author_email="[email protected]", | ||
maintainer="Viktor Hercinger", | ||
|
@@ -54,9 +49,9 @@ | |
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.2', | ||
'Programming Language :: Python :: 3.3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Topic :: Software Development', | ||
'Topic :: Software Development :: Testing', | ||
'Topic :: Documentation :: Sphinx', | ||
|
@@ -73,5 +68,6 @@ | |
requires=[ | ||
'nose', | ||
'sphinx', | ||
'typing_inspect', | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters