Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f902921

Browse files
authored
Add __lenght_hint__ magic method return type of int (#43)
1 parent 2e53b26 commit f902921

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ more transformations. The following are supported:
4343
- `__str__` returns `str`
4444
- `__repr__` returns `str`
4545
- `__len__` returns `int`
46+
- `__length_hint__` returns `int`
4647
- `__init__` returns `None`
4748
- `__del__` returns `None`
4849
- `__bool__` returns `bool`

autotyping/autotyping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class State:
6767
"__str__": "str",
6868
"__repr__": "str",
6969
"__len__": "int",
70+
"__length_hint__": "int",
7071
"__init__": "None",
7172
"__del__": "None",
7273
"__bool__": "bool",

tests/test_codemod.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,23 @@ def __not_str__():
281281
"""
282282
self.assertCodemod(before, after, annotate_magics=True)
283283

284+
def test_annotate_magics_len(self) -> None:
285+
before = """
286+
def __len__():
287+
pass
288+
289+
def __length_hint__():
290+
pass
291+
"""
292+
after = """
293+
def __len__() -> int:
294+
pass
295+
296+
def __length_hint__() -> int:
297+
pass
298+
"""
299+
self.assertCodemod(before, after, annotate_magics=True)
300+
284301
def test_exit(self) -> None:
285302
before = """
286303
def __exit__(self, typ, value, tb):

0 commit comments

Comments
 (0)