Skip to content

Commit

Permalink
Remove experimental type inference code (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-yz-liu authored Dec 13, 2023
1 parent 819f6df commit 57017b8
Show file tree
Hide file tree
Showing 92 changed files with 5 additions and 10,092 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ __pycache__/
# DS_Store
*.DS_Store

# .png files in test_type_inference
tests/test_type_inference/png*

# Sphinx documentation build files
docs/_build

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ For more information on these checkers, please see the
[Pylint release notes](http://pylint.pycqa.org/en/latest/whatsnew/index.html). Note that the above
list only contains the Pylint checkers enabled by default in PythonTA.

### Internal

- Remove experimental type inference code.

## [2.6.4] - 2024-11-10

### Bug fixes
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ include README.md
include python_ta/config/.pylintrc
include python_ta/config/messages_config.toml
include python_ta/reporters/templates/*
include python_ta/typecheck/typeshed/*
8 changes: 0 additions & 8 deletions examples/nodes/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@
ctx=<Context.Store: 2>,
value=AssignName(name='b'))])],
value=Name(name='d'))
Type-checking:
- Single identifiers are associated with the type of the expression on the RHS of the =.
- For (unpacking) tuple/list assignment, the RHS must be an iterable of the same length as
the number of identifiers on the LHS.
- An exception is when the * operator is used preceding a variable,
in this case, the remaining values in the iterable will assigned to
that variable as a list.
"""

# Example 1
Expand Down
4 changes: 0 additions & 4 deletions examples/nodes/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
Attribute(
attrname='colour',
expr=Name(name='snake'))
Type-checking:
The type of `expr` is resolved, and attrname is looked up for that type.
(Currently in TypeStore only, for built-in types.)
"""

snake.colour
8 changes: 0 additions & 8 deletions examples/nodes/aug_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
- value (Optional[NodeNG])
- A single node to be assigned to target.
Type-checking:
See https://docs.python.org/3.6/reference/datamodel.html#emulating-numeric-types.
Attempt to type-check the method call directly corresponding to 'op' (e.g.,
'__iadd__' for '+='). Otherwise, fallback to the corresponding standard
operator (e.g., '__add__' for '+='), making sure to auto-convert arguments
if necessary (as in BinOp).
Example:
AugAssign(
op='+=',
Expand Down
12 changes: 0 additions & 12 deletions examples/nodes/bin_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@
Refer to URL below for more information:
https://docs.python.org/3/library/operator.html?highlight=operator#module-operator
Type-checking:
First, attempt to convert the left and right expression to a "common type" as per
https://docs.python.org/3.6/reference/expressions.html?#arithmetic-conversions,
Translate the operator into the corresponding method, and attempt to type-check
the method call using the converted arguments.
Otherwise, proceed as per
https://docs.python.org/3.6/reference/datamodel.html#emulating-numeric-types
Note that if both the calls to the standard method (e.g., '__add__') and the
reflected method (e.g., '__radd__') fail to type-check, the failure corresponds
to the method that was prioritized.
"""

1 + 2
Expand Down
4 changes: 0 additions & 4 deletions examples/nodes/bool_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
BoolOp(
op='and',
values=[Const(value=1), Const(value=2)])])
Type-checking:
If all of the values have the type type, that type is used as the type of the of BoolOp itself.
Otherwise, the type of the BoolOp is Any.
"""

# Example 1
Expand Down
4 changes: 0 additions & 4 deletions examples/nodes/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
expr=Name(name='self')),
args=[Name(name='x')],
keywords=None)
Type-checking:
The type of func must be a function type; the argument types are matched with the parameter types
of the function. The type of the Call expression itself is equal to the return type of the function.
"""

# Example 1
Expand Down
4 changes: 0 additions & 4 deletions examples/nodes/class_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ class definition.
Name(name='base2')],
keywords=[],
body=[Pass()])
Type-checking:
The class name is added to the parent's type environment.
The class' instance variables and methods are used to update the global TypeStore.
"""


Expand Down
6 changes: 0 additions & 6 deletions examples/nodes/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
ops=[
['<', Const(value=1)],
['!=', Const(value=1)]])
Type-checking:
An individual comparison is converted to its corresponding method and type-checked.
Multiple comparisons in a single expression are type-checked in left-to-right order.
If each comparison returns the same type, that type is set for the entire Compare node.
Otherwise, the type of the Compare node is Any.
"""

0 < 1 != 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/comprehension.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
Compare(
left=Name(name='b'),
ops=[['<', Const(value=2)]])])
Type-checking:
Unify the target against the "contained" type in the iterable.
"""

# Example 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
Example 2:
Const(value=b'6')
Type-checking:
The type of a Const node is the type of its value attribute.
"""

1
Expand Down
5 changes: 0 additions & 5 deletions examples/nodes/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
Representation tree of Dict nodes show each KVP as a list;
however, the actual .items attribute stores each KVP as a tuple.
Type-checking:
Type is dict[K, V], where K is the most specific class that every key
of the dictionary is an instance of, and V is the most specific class that
every value of the dictionary is an instance of.
"""

# Example 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/dict_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
target=AssignName(name='y'),
iter=Name(name='b'),
ifs=[])])
Type-checking:
The type of the DictComp is dict[K, V], where K is the type of key and V is the type of value.
"""

# Example 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/dict_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
'value' in the [key, value] pair of the outermost Dict node.
This is node is NOT created when passing a dictionary into a function using ** (e.g. f(**x))
Type-checking:
- To be documented
"""

# Example 1
Expand Down
4 changes: 0 additions & 4 deletions examples/nodes/for.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
iter=Name(name='some_iterable'),
body=[Break()],
orelse=[])
Type-checking:
Unify the target against the "contained" type in the iterable.
"""

# Example 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/formatted_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
* NOTE : The example above is of a FormattedValue Node "{3.14159:.3}'" within
a JoinedStr Node "f'{3.14159:.3}'".
Type-checking:
- To be documented
"""

# Example 1
Expand Down
7 changes: 0 additions & 7 deletions examples/nodes/function_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@
type_comment_posonlyargs=[]),
returns=None,
body=[Pass()])
Type-checking:
We infer types for the arguments and return type based on the function body;
the return type is inferred as None if there are no Return nodes in the body.
This inferred type is unified with any type annotations that appear in the function
header, and finally this type is used to update the environment in which this function
declaration appears.
"""


Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/generator_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
args=[Name(name='i')],
keywords=None),
ifs=[])])
Type-checking:
The type of the GeneratorExp is Generator[T, None, None], where T is the type of elt.
"""

# Example
Expand Down
5 changes: 0 additions & 5 deletions examples/nodes/if_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
left=Name(name='x'),
right=Name(name='y')),
orelse=Name(name='something'))
Type-checking:
The type of the expression is the same as the type of the body and orelse expressions
(they must have the same type).
"""

# Example 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/joined_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
* Note that there is another JoinedStr in the format_spec of the FormattedValue.
This JoinedStr contains a str Const representing how to format a FormattedValue value
Type-checking:
- To be documented
"""

# Example 1
Expand Down
5 changes: 0 additions & 5 deletions examples/nodes/lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
op='+',
left=Name(name='x'),
right=Name(name='y')))
Type-checking:
The inferred type is a Callable with arguments inferred from the body of the
lambda expressions and whose return type is the inferred type of the body.
"""

# Example 1
Expand Down
5 changes: 0 additions & 5 deletions examples/nodes/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
elts=[Const(value=7), Const(value=8)]))
Example 3 demonstrates a Store context instead of Load
Type-checking:
Type is list[T], where T is the most specific class that every element
of the list is an instance of.
"""

# Example 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/list_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
Const(value=5),
Const(value=6)]),
ifs=[])])
Type-checking:
The type of the ListComp is list[T], where T is the type of elt.
"""

# Example 1
Expand Down
4 changes: 0 additions & 4 deletions examples/nodes/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
Example:
Name(name='my_var')
Type-checking:
- The type of a name is determined by looking it up in the *type environment* of its
enclosing scope.
"""

my_var
4 changes: 0 additions & 4 deletions examples/nodes/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
Const(value=1),
Const(value=2),
Const(value='hi')]
Type-checking:
Type is set[T], where T is the most specific class that every element
of the list is an instance of.
"""

# Example 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/set_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
ifs=[Compare(
left=Name(name='x'),
ops=[['<', Name(name='y')]])])])
Type-checking:
The type of the SetComp is set[T], where T is the type of elt.
"""

# Example 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
op='-',
operand=Const(value=1)),
step=Const(value=3)))
Type-checking:
Delegate to the __init__ constructor for slice, setting type to 'slice' on success.
"""

# Example 1
Expand Down
3 changes: 0 additions & 3 deletions examples/nodes/subscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
ctx=<Context.Load: 1>,
value=Name(name='x'),
slice=Const(value=0))
Type-checking:
Delegates to the methods __getitem__, __setitem__, or __delitem__, depending on context.
"""

x[0]
3 changes: 0 additions & 3 deletions examples/nodes/unary_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
UnaryOp(
op='~',
operand=Const(value=72))
Type-checking:
Translate the operator into the corresponding method, and type-check the method call.
"""

# Example 1:
Expand Down
Loading

0 comments on commit 57017b8

Please sign in to comment.