Skip to content

Instantly share code, notes, and snippets.

View JelleZijlstra's full-sized avatar

Jelle Zijlstra JelleZijlstra

View GitHub Profile
@JelleZijlstra
JelleZijlstra / deprecations.md
Created December 31, 2022 00:18
Deprecations in CPython

This contains some notes in connection to an in-progress PEP about deprecation support in the type system.

Briefly, the proposals being considered are:

  • @deprecated decorator for functions and classes
  • Deprecated[T] modifier for parameter and attribute types

I looked for usage of deprecations in the CPython codebase and whether some variation of this proposal could cover them, in the sense that it would be possible to write a stub that allows type checkers to detect code that would trigger the deprecation.

% flake8 --select=Y093 stdlib stubs
stdlib/zipapp.pyi:5:1: Y093 Use typing_extensions.TypeAlias for type aliases
stdlib/profile.pyi:10:1: Y093 Use typing_extensions.TypeAlias for type aliases
stdlib/socketserver.pyi:7:1: Y093 Use typing_extensions.TypeAlias for type aliases
stdlib/socketserver.pyi:8:1: Y093 Use typing_extensions.TypeAlias for type aliases
stdlib/gzip.pyi:9:1: Y093 Use typing_extensions.TypeAlias for type aliases
stdlib/gzip.pyi:10:1: Y093 Use typing_extensions.TypeAlias for type aliases
stdlib/gzip.pyi:11:1: Y093 Use typing_extensions.TypeAlias for type aliases
stdlib/itertools.pyi:24:1: Y093 Use typing_extensions.TypeAlias for type aliases
stdlib/itertools.pyi:26:1: Y093 Use typing_extensions.TypeAlias for type aliases
def _parse_callable_arg_list(args: Sequence[object]) -> Sequence[SigParameter]:
return [
SigParameter(f".arg{i}", ParameterKind.POSITIONAL_ONLY, annotation=parse_type(arg))
for i, arg in enumerate(args)
]
# Proposed "nested" approach
def parse_callable(node: Union[CallableType, AsyncCallableType]) -> Value:
return_value = parse_type(node.returns)
Only in stdlib/3/: cgi.pyi # done
Only in stdlib/2/: commands.pyi # removed in py3
Only in stdlib/2/: compileall.pyi # done
Only in stdlib/3/: concurrent # new in 3
Only in stdlib/2/: cookielib.pyi # moved
Only in stdlib/3/: curses
Only in stdlib/3/: dis.pyi # done
Only in stdlib/2/: distutils
Only in stdlib/2/: exceptions.pyi # removed in py3
Only in stdlib/2/: future_builtins.pyi # removed in py3
$ diff stdlib/3/codecs.pyi stdlib/2and3/codecs.pyi
2c2
< # https://docs.python.org/3/library/codecs.html
---
> # https://docs.python.org/2/library/codecs.html and https://docs.python.org/3/library/codecs.html
17c17
< # bytes is the raw form and str is the cooked form.
---
> # bytes (py2 str) is the raw form and str (py2 unicode) is the cooked form.
19a20
@JelleZijlstra
JelleZijlstra / gist:852a60f0fb1acf2da24b48a4f496851c
Created February 27, 2017 05:22
diff between py2 and 2and3
$ diff stdlib/2/codecs.pyi stdlib/2and3/codecs.pyi
2c2
< # https://docs.python.org/2/library/codecs.html
---
> # https://docs.python.org/2/library/codecs.html and https://docs.python.org/3/library/codecs.html
9d8
< Optional,
18c17
< # str is the raw form and unicode is the cooked form.
---
@JelleZijlstra
JelleZijlstra / gist:0aaeda5bb10cca3cf7fdc649ae2304ea
Created February 27, 2017 05:02
diff of py2 and py3 codecs.pyi
$ diff stdlib/2/codecs.pyi stdlib/3/codecs.pyi
2c2
< # https://docs.python.org/2/library/codecs.html
---
> # https://docs.python.org/3/library/codecs.html
9d8
< Optional,
18c17
< # str is the raw form and unicode is the cooked form.
---