8000 [BEAM-7746] Add python type hints (part 1) (#9915) · apache/beam@df37616 · GitHub
[go: up one dir, main page]

Skip to content

Commit df37616

Browse files
chadrikpabloem
authored andcommitted
[BEAM-7746] Add python type hints (part 1) (#9915)
* Address issues with a few missing modules/objects * Ignore some objects missing from typeshed * Ignore an issue regarding asymmetrical property getter/setter * Ignore unavoidable errors Many of these (those marked with [misc]) are due to mypy taking issue with: - the use of invalid type objects (typehints not typing) - the use of type objects at runtime * Ignore some conditional imports in tests * Ignore functions missing from typeshed * Add tests for Timestamp/Duration comparisons * Ignore errors about dynamic base classes This problem will be fixed when the next version of mypy is released * Ignore some monkey-patching for tests * Consolidate python build requirements This resolves a pip conflict that was happening between setupVirtualenv task and the tox task by ensuring that everything agrees on the same set of versions. * Ignore a difficult scenario where None is sometimes unsafe `None` is only safe to pass as the context to Coder.to_runner_api() when we know that the Coder class does not have components, otherwise the context is used to find and convert them. We could remove the need for special case `ignores` by reorganizing our Coder class hierarchy to add a CompoundCoder base class or mixin. Right now this is the only place in the code that we need to ignore this problem, so it's not worth tackling now. * Add a mypy lint job The test runs but error status is ignored. * Workaround a bug in pylint pylint-dev/pylint#3217 * Add type annotations to bulk of python codebase There are no meaningful runtime changes in this commit. * Silence errors about overriding methods. This seems to be fine to do on an instance as long as the types match, but not on a class. * Address review notes * Rebase fixup
1 parent ac3f592 commit df37616

File tree

133 files changed

+3164
-711
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+3164
-711
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ sdks/java/maven-archetypes/examples-java8/src/main/resources/archetype-resources
3535
**/dist/**/*
3636
**/distribute-*/**/*
3737
**/env/**/*
38+
**/.mypy_cache
39+
**/.dmypy.json
3840
sdks/python/**/*.c
3941
sdks/python/**/*.so
4042
sdks/python/**/*.egg

buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ class BeamModulePlugin implements Plugin<Project> {
17731773
project.exec { commandLine virtualenvCmd }
17741774
project.exec {
17751775
executable 'sh'
1776-
args '-c', ". ${project.ext.envdir}/bin/activate && pip install --retries 10 --upgrade tox==3.11.1 grpcio-tools==1.3.5"
1776+
args '-c', ". ${project.ext.envdir}/bin/activate && pip install --retries 10 --upgrade tox==3.11.1 -r ${project.rootDir}/sdks/python/build-requirements.txt"
17771777
}
17781778
}
17791779
// Gradle will delete outputs whenever it thinks they are stale. Putting a

sdks/python/.pylintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ disable =
143143
unnecessary-lambda,
144144
unnecessary-pass,
145145
unneeded-not,
146+
unsubscriptable-object,
146147
unused-argument,
147148
unused-wildcard-import,
148149
useless-object-inheritance,
@@ -178,6 +179,7 @@ indent-after-paren=4
178179
ignore-long-lines=(?x)
179180
(^\s*(import|from)\s
180181
|^\s*(\#\ )?<?(https?|ftp):\/\/[^\s\/$.?#].[^\s]*>?$
182+
|# type:
181183
)
182184

183185
[VARIABLES]

0 commit comments

Comments
 (0)
0