Skip to content

allow mypy to use custom stdlib stubs #781

@Josverl

Description

@Josverl

in a Q&D test it is possible to allow mypy to use the
new 1.24.1 stubs ( that omit sys)

mypy --custom-typeshed-dir ./typings .
by adding :

  • typings\mypy_extensions.pyi

origin : typestub repo : stubs\mypy-extensions\mypy_extensions.pyi

PyPI : types-mypy-extensions

refs:

  1. https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-custom-typeshed-dir
  2. https://discuss.python.org/t/pep-561-s-module-resolution-order-seems-incorrect/55048
  3. Tweak the typing spec's module resolution to more closely emulate Python's runtime semantics python/typing#1772
QA test code fragment type check error
feat_aioble\community_code\sample_1.py:53: await asyncio.sleep_ms(4) # stubs-ignore: linter == "mypy"
feat_aioble\examples_bluetooth\ble_bonding_peripheral.py:140: key = sec_type, bytes(key) # stubs-ignore: linter == "mypy"
feat_asyncio\check_basics_01.py:31: tasks[x] = asyncio.create_task(bar2(x)) # stubs-ignore: linter=="mypy"
feat_asyncio\check_basics_03.py:9: await asyncio.sleep_ms(200 * n) # Pause by varying amounts # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\aiorepl.py:103: s = asyncio.StreamReader(sys.stdin) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\aiorepl.py:106: hist = [] * _HISTORY_LIMIT # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\aiorepl.py:173: cmd # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\aiorepl.py:180: sys.stdout.write(b) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\aiorepl.py:183: sys.stdout.write(b) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\aiorepl.py:191: sys.stdout.write(cmd) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\auart_hd.py:25: self.swriter = asyncio.StreamWriter(self.uart, {}) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\auart_hd.py:26: self.sreader = asyncio.StreamReader(self.uart) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\auart_hd.py:34: await self.swriter.awrite( # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\auart_hd.py:38: await asyncio.sleep_ms(300) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\auart_hd.py:51: self.swriter = asyncio.StreamWriter(self.uart, {}) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\auart_hd.py:52: self.sreader = asyncio.StreamReader(self.uart) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\auart_hd.py:68: await self.swriter.awrite("{}\r\n".format(command)) # stubs-ignore: linter=="mypy"
feat_asyncio\check_demo\roundrobin.py:21: await asyncio.sleep_ms(0) # stubs-ignore: linter=="mypy"
feat_networking\check_examples\http_client.py:18: s.write(b"GET / HTTP/1.0\r\n\r\n") # stubs-ignore: linter == "mypy"
feat_networking\check_examples\http_client.py:19: print(s.read()) # stubs-ignore: linter == "mypy"
feat_stdlib\check_array.py:5: ar = array.array("I", [0 for _ in range(NUM_LEDS)]) # stubs-ignore: linter == "mypy"
feat_stdlib\check_io.py:7: buffer_1 = io.StringIO(alloc_size) # stubs-ignore: version<=1.18.0 or linter == "mypy"
feat_stdlib\check_io.py:8: buffer_2 = io.BytesIO(alloc_size) # stubs-ignore: version<=1.18.0 or linter == "mypy"
feat_stdlib\check_io.py:12: buf = io.BufferedWriter(stream, 8) # stubs-ignore: linter == "mypy" Argument 1 to "BufferedWriter" has incompatible type "TextIOWrapper[_WrappedBuffer]"; expected "RawIOBase" [arg-type]
feat_stdlib\check_uio.py:7: buffer_1 = uio.StringIO(alloc_size) # stubs-ignore: linter == "mypy"
feat_stdlib\check_uio.py:8: buffer_2 = uio.BytesIO(alloc_size) # stubs-ignore: linter == "mypy"
feat_stdlib\check_sys\check_print_exception.py:3: from sys import print_exception # stubs-ignore: linter == "mypy"
feat_stdlib\check_sys\check_sys.py:24: sys.print_exception(exc) # stubs-ignore: linter == "mypy"
feat_stdlib\check_sys\check_sys.py:32: previous = sys.atexit(byebye) # stubs-ignore: linter == "mypy"

Metadata

Metadata

Assignees

Labels

mypyTypecheck issue reported by mypy

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions