“typing” is getting deprecated in Python
Summary
TLDRIn this video, the creator expresses frustration over the deprecation of types in Python's 'typing' module since version 3.9, which was not well communicated. The video demonstrates the use of 'typing.Iterable' and 'typing.Callable', which are now recommended to be replaced with 'collections.abc' equivalents. The speaker criticizes the lack of clear deprecation warnings and the implicit handling of this change, which they only discovered in Python 3.12, and calls for more transparency in such updates.
Takeaways
- 😕 The video discusses the deprecation of certain types in the `typing` module since Python 3.9.
- 👨💻 The presenter expresses frustration over the lack of clear communication regarding these deprecations.
- 🔍 The `typing.Iterable` and `typing.Callable` types are deprecated and should be replaced with `collections.abc.Iterable` and `collections.abc.Callable`.
- 📚 The presenter found out about the deprecations only recently, despite using Python 3.2 daily and keeping up with documentation.
- 💻 The video demonstrates how to use the deprecated types in a function example, which still works without warnings.
- 🚫 The deprecation is not flagged by tools like `mypy` or PyCharm, which the presenter finds concerning.
- 📝 The change is intended to minimize the runtime impact of the `typing` module, but the presenter questions the lack of deprecation warnings.
- 🔄 The deprecated types are simply aliases to the `collections.abc` module, which should be used instead.
- 🤔 The presenter is unsure why the change is being handled implicitly and wishes for clearer communication from Python developers.
- 🗣️ The video ends with a call for feedback from viewers on their thoughts about the handling of these deprecations.
Q & A
What is the main topic of the video?
-The main topic of the video is the deprecation of certain types in the 'typing' module in Python since version 3.9.
Why is the presenter upset in the video?
-The presenter is upset because they found out about the deprecation of types in the 'typing' module only recently, despite using Python 3.2 daily, and they feel that the way this change was handled was sneaky and not well communicated.
What is the alternative to 'typing.Iterable' after its deprecation?
-After the deprecation of 'typing.Iterable', the alternative is to use 'collections.ABC.Iterable' as recommended in the Python documentation.
What does the presenter demonstrate with the 'say_hello' function?
-The presenter demonstrates that the 'say_hello' function, which takes an iterable of names, works correctly with the deprecated 'typing.Iterable' type, but should instead use 'collections.ABC.Iterable'.
What is the purpose of the 'repeat' function shown in the video?
-The 'repeat' function is used to execute another function a specified number of times, and it uses the deprecated 'typing.Callable' type, which should be replaced with 'collections.ABC.Callable'.
What is the issue with the deprecation process as described by the presenter?
-The issue is that the deprecation of types in the 'typing' module is not well communicated, and the presenter only found out about it after several Python versions had been released.
Why did the Python developers deprecate certain types from the 'typing' module?
-The Python developers deprecated certain types to minimize the runtime impact of typing and to streamline the type annotations by directing users to use 'collections.ABC' instead.
How does the presenter feel about the lack of deprecation warnings for the 'typing' module types?
-The presenter is confused and frustrated by the lack of deprecation warnings, as they believe it should have been communicated more clearly to avoid confusion among developers.
What is the presenter's opinion on the future of deprecated types in the 'typing' module?
-The presenter wishes for more concrete information about whether the deprecated types will be removed from the 'typing' module in the future or not.
What does the presenter encourage viewers to do after watching the video?
-The presenter encourages viewers to share their thoughts on the deprecation of types in the 'typing' module and whether they were aware of the change or not in the comment section.
Outlines
😕 Python's Deprecated Typing Module
The speaker expresses frustration over the deprecation of types in Python's 'typing' module since version 3.9. They discuss the lack of visibility regarding this change, which they only discovered in Python 3.12. The video introduces a function 'say_hello' that uses the deprecated 'Iterable' type from the 'typing' module, which should now be replaced with 'collections.ABC'. The speaker emphasizes the importance of checking documentation directly for such updates, as their usual tools did not flag the deprecation.
😤 The Silent Deprecation of Python's Typing Features
Continuing the discussion on Python's 'typing' module, the speaker criticizes the implicit handling of deprecation, which they feel should have been more explicitly communicated. They mention the lack of deprecation warnings as a missed opportunity to inform developers of the need to update their code. The speaker also touches on the potential future removal of these deprecated features, expressing a desire for clearer communication from the Python development team. They conclude by inviting viewers to share their thoughts on the matter in the comments section.
Mindmap
Keywords
💡typing module
💡collections.ABC
💡deprecation
💡type hints
💡Iterable
💡Callable
💡mypy
💡backwards compatibility
💡runtime impact
💡documentation
Highlights
The video discusses the deprecation of certain types in the Python 'typing' module since version 3.9.
The creator expresses frustration over the lack of visibility regarding the deprecation.
Importing 'typing' as T and 'collections.ABC' as C is demonstrated.
A function 'say_hello' is created to illustrate the use of the 'iterable' type from the 'typing' module.
The video shows that using 'iterable' works fine in practice, even though it's deprecated.
The creator emphasizes the need to check the documentation for deprecation notices.
It is recommended to use 'collections.ABC' instead of 'typing' for collection types.
The video explains that 'typing' types are aliases to 'collections', making them equivalent.
A second function 'repeat' is introduced to demonstrate the use of the 'callable' type.
The 'callable' type is also deprecated and should be replaced with 'collections.ABC.Callable'.
The video criticizes the implicit handling of the deprecation, making it difficult to discover.
The creator discusses the intention behind deprecation to minimize runtime impact.
Deprecation warnings are not generated for these changes, which is a point of confusion.
The possibility of deprecated functionalities being removed in the future is mentioned.
The video ends with a call for community feedback on the handling of deprecations.
The creator invites viewers to share their thoughts on the deprecation process in the comments.
Transcripts
this video was brought to you by IND
dentle IO learning python Made Simple
how's it going everyone in today's video
we're going to be going over the typing
module and how most of the types inside
it are actually deprecated since python
3.9 I only recently found out about this
and that's why I'm kind of upset because
in my opinion the way they're handling
this is kind of sneaky anyway to dive
into what I want to talk about today I'm
going to import typing as T and then I'm
also going to import collections. ABC as
C next I'm going to create a function
that says say hello and that's going to
take some names to actually say hello to
and names should be of type itable so
here I'm going to refer to our typing
module and use the iterable
type and this function will return none
because we are only executing code but
next we'll type in forame in names print
name names or name and at a first glance
this should look quite fine I mean if
you type in say hello you add some names
such as
Bob and Luigi the program is going to
work perfectly fine because we passed in
a type which was of type iterable if we
were to pass in a number that would not
work because an integer is not of type
iterable our type has to be iterable for
this function to actually work correctly
irly and even if we were to run mypi so
we type in mypi main.py which is my
current file we would have no issues
found in this source
file now what I absolutely hate about
this is that typing. iterable is
deprecated since python 3.9 which is
ridiculous that it took me until python
3.12 to find out about and maybe other
code editors or other type Checkers are
more strict about this but my pi and
High charm show no signs of life when it
comes to this deprecation and to
actually see that this is deprecated you
need to go to the docs directly it's
written in the docs that everything's
deprecated since python
3.9 such as this itable it's going to
tell you to use collections. ABC instead
and this is since python 3.9 which again
is insane cuz I'm using python 3.2 I use
Python nearly every day and I only found
out about it recently because this
deprecation is incredibly implicit so
what you're supposed to do instead for
these collection types is use
collections. APC which I gave an alias
of C so I can just quickly do this and
this would be the correct and modern way
to annotate your types we're just
importing from collections. ABC now
instead of typing personally I hate this
change because I thought typing is just
such a straightforward module it has one
place that contains all the types you
need so it's just easy to refer to that
module if you want to use any type you
want now I'm complaining of course but I
will get used to this I get used to all
the changes that's what we do as
developers I just hate how implicit this
change is being brought about I mean
again it took me three python versions
to find out that I've been using a
deprecated module all this time but
let's go back to typing. iterable and go
to the
Declaration what you're going to notice
is that all the types or all of the
types that are getting deprecated from
the typing module are actually just
aliases to the collections module now
which just means that if you refer to
something from the typing module it just
points to the one that's in the
collections module t. iterable and c.
iterable are exactly the same thing but
let's take a look at another example and
here I'm going to create a function
called
repeat which is going to take a function
and repeat that function and I'm going
to use the callable type
here and we want to provide the amount
of time s we want to repeat that
function that will return none cuz we're
only executing code and then for I in
range times execute that function then
let's create a simple function that says
hello returns
nothing and we will print hello just so
we can test out our repeat function here
we can type in repeat Hello without the
parenthesis and times will be set to
three so that when we run this we should
get that function repeated three times
once again everything's running
perfectly even if we open up mypie and
run that we're going to find no issues
in this source file even if we're using
a deprecated type except this time if we
actually go to the
Declaration the colable doc will have a
message that says this is a deprecated
Alias to collections. abc. colable and
if we actually go to the docs once again
it's going to be deprecated since python
3.9 and it's going to redirect you to
collections. ABC where you will find the
appropriate type which then means you
can change it to c. colable which
actually uses the correct module for
this type but again this change isn't
really the worst thing in the world what
I hate the most about it is how
implicitly it's being handled the fact
that I had to learn this from one of you
guys in the comment section three
versions later is what the disturbs me I
read the updates I read the
documentation all the time but still I
had no idea until python 3.12 that this
was actually a thing and they write that
the intention is to minimize the runtime
impact of typing I personally don't know
how big that impact actually is but they
State very clearly that this deprecation
will not generate deprecation warnings
and I don't understand that I don't
understand why they wouldn't generate
any deprecation warnings for something
like this and they continue to write
that the deprecated function
functionality may eventually be removed
from the typing module they wrote May
here I don't understand why they write
may I don't know if they're still
thinking about this change or not but I
wish it was a bit more concrete it's
really like telling somebody hey maybe
in the future you'll be able to use this
maybe you won't we're still deciding or
maybe it's for backwards compatibility I
know that it's not an easy decision or
it's not as easy as saying you should
just remove it or you should just keep
it I only wish they would put something
a bit more concrete out for all of us so
that we know that something's going to
change or that something's not going to
change instead of having us find out in
October
20202 when they actually deprecated if
they deprecated but yeah that's actually
all I wanted to cover in today's video
do let me know what you think about this
change in the comment section down below
whether you already knew about it or
whether this is the first time you hear
about it I would love to hear about that
in the comment section down below also
your takes on the matter I mean of
course course I can get very angry about
this but I would love to hear whether
you think this actually makes sense
whether it's good that they pass it
implicitly or whether it's completely my
fault that I didn't read the
documentation close enough when python
3.9 was released so yeah with all that
being said as always thanks for watching
and I'll see you in the next video
Ver Más Videos Relacionados
Some New Features in Python 3.11
Python Bytecode: An Introductory Tutorial
Pydantic Tutorial • Solving Python's Biggest Problem
Piracy is COMPLETELY justified: Louis tries NetFlix & remembers why
The Biggest Problem With ChatGPT | Tsoding
'I'm Tired Of This': Ralph Norman Admonishes Jerry Nadler During Tense Exchange At Hearing
5.0 / 5 (0 votes)