OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why doesn't Python type checking raise an error for mismatch?

  • Thread starter Thread starter BugSpray
  • Start date Start date
B

BugSpray

Guest
Here's a trivial example, but something which I'm trying to make use of in a project.

Code:
"""Test typing problems."""

from typing import TypeAlias

Verb: TypeAlias = str


def concats_string(base: Verb) -> str:
    # Trivial example - should just append to the passed in value
    return " ".join([base, "World"])


greeting: str = "Hello"
print(concats_string(greeting))

I can't get MyPy, PyRight or pytype to raise an error about the function call.
(Indeed, the join function should be flagged too...)

I'm guessing this is expected behaviour, since different implementations don't complain - but what am I missing here?
Isn't this the point of TypeAlias and exactly what a type checker should flag?
<p>Here's a trivial example, but something which I'm trying to make use of in a project.</p>
<pre class="lang-py prettyprint-override"><code>"""Test typing problems."""

from typing import TypeAlias

Verb: TypeAlias = str


def concats_string(base: Verb) -> str:
# Trivial example - should just append to the passed in value
return " ".join([base, "World"])


greeting: str = "Hello"
print(concats_string(greeting))
</code></pre>
<p>I can't get MyPy, PyRight or pytype to raise an error about the function call. <br />
(Indeed, the <code>join</code> function should be flagged too...)</p>
<p>I'm guessing this is expected behaviour, since different implementations don't complain - but what am I missing here? <br />
Isn't this the point of TypeAlias and exactly what a type checker <em>should</em> flag?</p>
 

Latest posts

A
Replies
0
Views
1
Adrian-Mihai Enache
A
Top