Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #43 from alexmusa/master
Browse files Browse the repository at this point in the history
fix TypeError in mypy plugin with mypy==0.812
  • Loading branch information
jspahrsummers authored Mar 19, 2021
2 parents c8d46fe + fbb3bf6 commit 26adb4d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ class ExampleADT:
@property
def safe_string_pair(self) -> Optional[Tuple[str, str]]:
return self.match(empty=lambda: None,
integer=lambda: None,
string_pair=lambda a, b: tuple(a, b))
integer=lambda n: None,
string_pair=lambda a, b: (a, b))
```

However, additional fields _must not_ be added to the class, as the decorator will attempt to interpret them as ADT `Case`s (which will fail).
5 changes: 3 additions & 2 deletions adt/mypy_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def accessor_return(self) -> mypy.types.Type:
return self.types[0]
else:
return mypy.types.TupleType(
self.types, self.context.api.named_type('__builtins__.tuple'))
list(self.types),
self.context.api.named_type('__builtins__.tuple'))

def match_lambda(self,
return_type: mypy.types.Type) -> mypy.types.CallableType:
Expand Down Expand Up @@ -242,7 +243,7 @@ def _get_and_delete_cases(context: ClassDefContext
caseDefs.append(
_CaseDef(context=context,
name=get_name(var),
types=var.type.ret_type.args))
types=list(var.type.ret_type.args)))
removed.append(i)

for i in reversed(removed):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
yapf==0.27.0
mypy>=0.711, <=0.761
mypy>=0.711, <=0.812
coverage==4.5.3
hypothesis==4.24.5
coveralls==1.8.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
long_description = fh.read()

setup(name='algebraic-data-types',
version='0.2',
version='0.2.1',
author='Justin Spahr-Summers',
author_email='justin@jspahrsummers.com',
description='Algebraic data types for Python',
Expand Down
6 changes: 1 addition & 5 deletions tests/test_mypy_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@

class TestMyPyPlugin(unittest.TestCase):
def test_issue21(self) -> None:
# cf. https://github.com/jspahrsummers/adt/issues/21
self._call_mypy_on_source_file("issue21.py")

@unittest.expectedFailure # Issue #25 is still unfixed
def test_issue25(self) -> None:
# Activate it when working on it.
# cf. https://github.com/jspahrsummers/adt/issues/25
self._call_mypy_on_source_file("issue25.py")

@unittest.expectedFailure # Issue #26 is still unfixed
def test_issue26(self) -> None:
# Activate it when working on it.
# cf. https://github.com/jspahrsummers/adt/issues/26
self._call_mypy_on_source_file("issue26.py")

@unittest.expectedFailure # Fails because issue #26 is still unfixed
def test_readme_examples(self) -> None:
readme_code = extract_code_from_readme()

Expand Down

0 comments on commit 26adb4d

Please sign in to comment.