Deprecation of Python Typing Module

Aug 27, 2024

Lecture Notes: Understanding the Deprecation of Typing Module in Python

Introduction

  • Topic: Changes in the Python typing module and its deprecation since Python 3.9.
  • Main Concern: The deprecation has been implicit, causing surprise and frustration among developers.

Key Points

Importing Modules

  • Import typing as T and collections.abc as C.
  • Example: Creating a say_hello function using Iterable type from typing.

Example Function: say_hello

  • Function: Takes names as an iterable type and returns None.
  • Usage: Works fine with iterable types like lists, but not with integers or other non-iterable types.
  • Testing: Running mypy on the file shows no issues, despite the deprecation.

Deprecation Details

  • typing.Iterable and similar types are deprecated since Python 3.9.
  • Documentation: Deprecation noted only in official documentation, not indicated by tools like mypy or PyCharm.
  • Recommendation is to use collections.abc for collection types.

Example Function: repeat

  • Function: Uses Callable type for repeating a function a specified number of times.
  • Deprecation: Similar issue as Iterable, with Callable being a deprecated alias to collections.abc.Callable.

Implicit Changes

  • Frustration: Changes are implicit with no warnings, leading to confusion.
  • Documentation: Updates are not generating deprecation warnings, potentially due to runtime impact concerns.

Response to Change

  • Developers need to adapt quickly to these changes.
  • Criticism: Lack of clear communication and decision-making in the deprecation process.

Conclusion

  • Community Feedback: Encourages comments on awareness and opinions about the change.
  • Personal Reflection: Questions personal responsibility in keeping up with documentation.

Closing Remarks

  • Engagement: Encourages sharing thoughts in the comments.
  • Acknowledgment: Thanks viewers for watching and promises more updates in future videos.