TL;DR: You don't.
That is not how types work in general. It's like asking "how can I check if something is just a bear, but not a polar bear, grizzly bear, or any other subtype of bear?" What does that even mean?
If something can be subtyped, there is no way to do what you are asking.
Note that I am talking about static type checking here, not about runtime logic. Of course you can do this:
assert type(x) is str
That will ensure that x is of the str class and not of a subclass, but there are good reasons, why that is usually discouraged in favor of this:
assert isinstance(x, str)
That has almost nothing to do with type annotations of variables though.
By default, a type can have any number of descendant types. If you want to have a custom type, which is final, i.e. subtypes shall not exist, you can make use of PEP 591:
from typing import final
@final
class MyStr(str):
pass
if __name__ == '__main__':
x: MyStr
x = MyStr("abc")
The relevant thing for the type checker here is that MyStr is final, which means that it will give you an error the moment you try to subclass MyStr without even concerning itself with whether you assign a value of that subclass to x later on. Taking mypy for example, if you do this:
from typing import final
@final
class MyStr(str):
pass
class OtherStr(MyStr): # this is where the error occurs
pass
if __name__ == '__main__':
x: MyStr
x = OtherStr("abc") # irrelevant at this point
It will not complain about the last line at all. Instead it will only say:
error: Cannot inherit from final class "MyStr" [misc]
In other words, the moment you try and create a subclass, the rest of the things you do with that class no longer matter because they are by definition invalid.
If you really want to, you can of course shadow str, but this will come with a bunch of caveats:
from builtins import str as built_in_str
from typing import final
@final
class str(built_in_str):
pass
if __name__ == '__main__':
x: str
x = str("abc")
I think this is a very bad idea. One reason is that you won't be able to just use a string literal "abc" to assign to x because that gives you a builtin.str object. But I think you can imagine whole lot of other problems.
Hope this makes sense.