Skip to content

Subclasses vs union of types vs TypeVar #2039

Answered by srittau
hunterhogan asked this question in Q&A
Discussion options

You must be logged in to vote

Maybe this will help a bit:

  • If the type is ast.AST, I think ast.Module will match.
  • If the type is hasDOTarg, I think ast.keyword will match.
  • If the type is kuo, I think ast.Assign will match because it is a subclass of ast.stmt.

Unless I've overlooked something, this is correct, although I'd like to point out that a type var should always be used at least twice in a context to make sense. I.e.:

def ImaFunction(goat: kuo):
    pass

Using kuo here has no benefit and you could just use ast.stmt directly instead.

But, this system of using TypeAlias, union, and subclasses, for example, doesn't always work when I expect it to work.

[...]

    @staticmethod
    def target(node: hasDOTtarget) ->

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@hunterhogan
Comment options

@srittau
Comment options

Answer selected by hunterhogan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants