-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shaygan <[email protected]>
- Loading branch information
Showing
5 changed files
with
270 additions
and
4 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
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
41 changes: 41 additions & 0 deletions
41
typechecker/test_data/inputs/conformance_tests/specialtypes_none.py
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,41 @@ | ||
""" | ||
Tests the handling of builtins.None in a type annotation. | ||
""" | ||
|
||
# Specification: https://typing.readthedocs.io/en/latest/spec/special-types.html#none | ||
|
||
from types import NoneType | ||
from typing import Hashable, Iterable, assert_type | ||
|
||
|
||
# > When used in a type hint, the expression None is considered equivalent to type(None). | ||
|
||
|
||
def func1(val1: None) -> None: | ||
assert_type(val1, None) | ||
t1: None = None | ||
return None # OK | ||
|
||
|
||
func1(None) # OK | ||
func1(type(None)) # E | ||
|
||
# None is hashable | ||
none1: Hashable = None # OK | ||
|
||
# None is not iterable | ||
none2: Iterable = None # E: not iterable | ||
|
||
|
||
None.__class__ # OK | ||
None.__doc__ # OK | ||
None.__eq__(0) # OK | ||
|
||
|
||
def func2(val1: type[None]): | ||
assert_type(val1, type[None]) | ||
|
||
|
||
func2(None.__class__) # OK | ||
func2(type(None)) # OK | ||
func2(None) # E: not compatible |
162 changes: 162 additions & 0 deletions
162
...cker/test_data/output/enderpy_python_type_checker__checker__tests__specialtypes_none.snap
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,162 @@ | ||
--- | ||
source: typechecker/src/checker.rs | ||
description: "1: \"\"\"\n2: Tests the handling of builtins.None in a type annotation.\n3: \"\"\"\n4: \n5: # Specification: https://typing.readthedocs.io/en/latest/spec/special-types.html#none\n6: \n7: from types import NoneType\n8: from typing import Hashable, Iterable, assert_type\n9: \n10: \n11: # > When used in a type hint, the expression None is considered equivalent to type(None).\n12: \n13: \n14: def func1(val1: None) -> None:\n15: assert_type(val1, None)\n16: t1: None = None\n17: return None # OK\n18: \n19: \n20: func1(None) # OK\n21: func1(type(None)) # E\n22: \n23: # None is hashable\n24: none1: Hashable = None # OK\n25: \n26: # None is not iterable\n27: none2: Iterable = None # E: not iterable\n28: \n29: \n30: None.__class__ # OK\n31: None.__doc__ # OK\n32: None.__eq__(0) # OK\n33: \n34: \n35: def func2(val1: type[None]):\n36: assert_type(val1, type[None])\n37: \n38: \n39: func2(None.__class__) # OK\n40: func2(type(None)) # OK\n41: func2(None) # E: not compatible\n" | ||
expression: result | ||
--- | ||
Line 1: """ | ||
Tests the handling of builtins.None in a type annotation. | ||
""" | ||
Expr types in the line --->: | ||
""" | ||
Tests the handling of builtins.None in a type annotation. | ||
""" => (class) str | ||
|
||
--- | ||
Line 5: from types import NoneType | ||
|
||
Expr types in the line --->: | ||
types => Module | ||
NoneType => (class) NoneType | ||
|
||
--- | ||
Line 6: from typing import Hashable, Iterable, assert_type | ||
|
||
Expr types in the line --->: | ||
typing => Module | ||
Hashable => (class) Hashable | ||
Iterable => (class) typing.Iterable[TypeVar[_T_co, ]] | ||
assert_type => (function) Callable[[TypeVar[_T, ], (class) object], TypeVar[_T, ]] | ||
|
||
--- | ||
Line 12: def func1(val1: None) -> None: | ||
|
||
Expr types in the line --->: | ||
func1 => (function) Callable[[None], None] | ||
val1: None => None | ||
None => None | ||
None => None | ||
|
||
--- | ||
Line 13: assert_type(val1, None) | ||
|
||
Expr types in the line --->: | ||
assert_type => (function) Callable[[TypeVar[_T, ], (class) object], TypeVar[_T, ]] | ||
assert_type(val1, None) => TypeVar[_T, ] | ||
val1 => None | ||
None => None | ||
|
||
--- | ||
Line 14: t1: None = None | ||
|
||
Expr types in the line --->: | ||
t1 => None | ||
None => None | ||
|
||
--- | ||
Line 15: return None # OK | ||
|
||
Expr types in the line --->: | ||
None => None | ||
|
||
--- | ||
Line 18: func1(None) # OK | ||
|
||
Expr types in the line --->: | ||
func1 => (function) Callable[[None], None] | ||
func1(None) => None | ||
None => None | ||
|
||
--- | ||
Line 19: func1(type(None)) # E | ||
|
||
Expr types in the line --->: | ||
func1 => (function) Callable[[None], None] | ||
func1(type(None)) => None | ||
type => (class) type | ||
type(None) => (class) type | ||
None => None | ||
|
||
--- | ||
Line 22: none1: Hashable = None # OK | ||
|
||
Expr types in the line --->: | ||
none1 => (class) Hashable | ||
None => None | ||
|
||
--- | ||
Line 25: none2: Iterable = None # E: not iterable | ||
|
||
Expr types in the line --->: | ||
none2 => (class) typing.Iterable[TypeVar[_T_co, ]] | ||
None => None | ||
|
||
--- | ||
Line 28: None.__class__ # OK | ||
|
||
Expr types in the line --->: | ||
None => None | ||
None.__class__ => (function) Callable[[Unknown], (class) builtins.type[(class) Self]] | ||
|
||
--- | ||
Line 29: None.__doc__ # OK | ||
|
||
Expr types in the line --->: | ||
None => None | ||
None.__doc__ => Union[(class) str, None] | ||
|
||
--- | ||
Line 30: None.__eq__(0) # OK | ||
|
||
Expr types in the line --->: | ||
None.__eq__ => (function) Callable[[Unknown, (class) object], (class) bool] | ||
None.__eq__(0) => (class) bool | ||
0 => (class) int | ||
|
||
--- | ||
Line 33: def func2(val1: type[None]): | ||
|
||
Expr types in the line --->: | ||
func2 => (function) Callable[[(class) builtins.type[None]], Unknown] | ||
val1: type[None] => (class) builtins.type[None] | ||
type[None] => (class) type | ||
|
||
--- | ||
Line 34: assert_type(val1, type[None]) | ||
|
||
Expr types in the line --->: | ||
assert_type => (function) Callable[[TypeVar[_T, ], (class) object], TypeVar[_T, ]] | ||
assert_type(val1, type[None]) => TypeVar[_T, ] | ||
val1 => (class) builtins.type[None] | ||
type => (class) type | ||
type[None] => (class) type | ||
None => None | ||
|
||
--- | ||
Line 37: func2(None.__class__) # OK | ||
|
||
Expr types in the line --->: | ||
func2 => (function) Callable[[(class) builtins.type[None]], Unknown] | ||
func2(None.__class__) => Unknown | ||
None => None | ||
None.__class__ => (function) Callable[[Unknown], (class) builtins.type[(class) Self]] | ||
|
||
--- | ||
Line 38: func2(type(None)) # OK | ||
|
||
Expr types in the line --->: | ||
func2 => (function) Callable[[(class) builtins.type[None]], Unknown] | ||
func2(type(None)) => Unknown | ||
type => (class) type | ||
type(None) => (class) type | ||
None => None | ||
|
||
--- | ||
Line 39: func2(None) # E: not compatible | ||
|
||
Expr types in the line --->: | ||
func2 => (function) Callable[[(class) builtins.type[None]], Unknown] | ||
func2(None) => Unknown | ||
None => None | ||
|
||
--- |