[ https://issues.apache.org/jira/browse/BEAM-8280?focusedWorklogId=411410&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-411410 ]
ASF GitHub Bot logged work on BEAM-8280: ---------------------------------------- Author: ASF GitHub Bot Created on: 27/Mar/20 21:51 Start Date: 27/Mar/20 21:51 Worklog Time Spent: 10m Work Description: robertwb commented on pull request #11232: [BEAM-8280] Document Python 3 annotations support URL: https://github.com/apache/beam/pull/11232#discussion_r399553756 ########## File path: website/src/documentation/sdks/python-type-safety.md ########## @@ -23,38 +23,58 @@ Python is a dynamically-typed language with no static type checking. Because of The Apache Beam SDK for Python uses **type hints** during pipeline construction and runtime to try to emulate the correctness guarantees achieved by true static typing. Additionally, using type hints lays some groundwork that allows the backend service to perform efficient type deduction and registration of `Coder` objects. -Python version 3.5 introduces a module called **typing** to provide hints for type validators in the language. The Beam SDK for Python, based on Python version 2.7, implements a subset of [PEP 484](https://www.python.org/dev/peps/pep-0484/) and aims to follow it as closely as possible in its own typehints module. +Python version 3.5 introduces a module called **typing** to provide hints for type validators in the language. +The Beam SDK for Python implements a subset of [PEP 484](https://www.python.org/dev/peps/pep-0484/) and aims to follow it as closely as possible in its own typehints module. + +These flags control Beam type safety: +- `--no_pipeline_type_check` + + Disables type checking during pipeline construction. + Default is to perform these checks. +- `--runtime_type_check` + + Enables runtime type checking of every element. + This may affect pipeline performance, so the default is to skip these checks. ## Benefits of Type Hints -The Beam SDK for Python includes some automatic type checking: for example, some `PTransform`s, such as `Create` and simple `ParDo` transforms, attempt to deduce their output type given their input. However, the Beam cannot infer types in all cases. Therefore, the recommendation is that you declare type hints to aid you in performing your own type checks if necessary. +The Beam SDK for Python includes some automatic type checking: for example, some `PTransforms`, such as `Create` and simple `ParDo` transforms, attempt to deduce their output type given their input. However, the Beam cannot infer types in all cases. Therefore, the recommendation is that you declare type hints to aid you in performing your own type checks if necessary. -When you use type hints, the runner raises exceptions during pipeline construction time, rather than runtime. For example, the runner generates an exception if it detects that your pipeline applies mismatched `PTransforms` (where the expected outputs of one transform do not match the expected inputs of the following transform). These exceptions are raised at pipeline construction time, regardless of where your pipeline will execute. Introducing type hints for the `PTransform`s you define allows you to catch potential bugs up front in the local runner, rather than after minutes of execution into a deep, complex pipeline. +When you use type hints, the runner raises exceptions during pipeline construction time, rather than runtime. For example, the runner generates an exception if it detects that your pipeline applies mismatched `PTransforms` (where the expected outputs of one transform do not match the expected inputs of the following transform). These exceptions are raised at pipeline construction time, regardless of where your pipeline will execute. Introducing type hints for the `PTransforms` you define allows you to catch potential bugs up front in the local runner, rather than after minutes of execution into a deep, complex pipeline. Review comment: I might lead with this paragraph, maybe even giving a very concrete example ("for example, giving an error when trying to apply a PTransform that expects a PCollection of strings to a PCollection of ints"). Then put the other paragraph about Beam not always being able to infer types next. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 411410) Time Spent: 11h 40m (was: 11.5h) > re-enable IOTypeHints.from_callable > ----------------------------------- > > Key: BEAM-8280 > URL: https://issues.apache.org/jira/browse/BEAM-8280 > Project: Beam > Issue Type: Bug > Components: sdk-py-core > Reporter: Udi Meiri > Assignee: Udi Meiri > Priority: Major > Time Spent: 11h 40m > Remaining Estimate: 0h > > See https://issues.apache.org/jira/browse/BEAM-8279 -- This message was sent by Atlassian Jira (v8.3.4#803005)