Skip to content

Using typing with older versions of Python #372

@achapkowski

Description

@achapkowski

How to use typing in older versions seems a bit unclear, can you provide an example of how to use typing with older versions of python?

This doesn't seem to do anything:

def greeting(name): # type: (str) -> str
    """documentations"""
    return ('Hello ' + name)

if __name__ == "__main__":
    print (greeting("World"))
    print (greeting(44)) # Doesn't catch invalid input type until i get to the string concat.

In addition, the __annotations__ property doesn't get added to the function:

import typing
def greeting(name): # type: (str) -> str
    """documentations"""
    return ('Hello ' + name)
print(greeting.__annotations__) # fails because doesn't exist.

Please advise how this back port should be used properly for developers who need to maintain compatibility with older versions of Python (2.7.12 and 3.4).

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions