Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Improve Python consistency: Use function_name(…) throughout (PEP8) #1399

Merged
merged 1 commit into from
Feb 29, 2016
Merged

[Python] Improve Python consistency: Use function_name(…) throughout (PEP8) #1399

merged 1 commit into from
Feb 29, 2016

Conversation

practicalswift
Copy link
Contributor

Background: See discussion with @modocache and @nadavrot in #1369. This is a follow-up to #1374.

The majority of Python function names in the repo are in lowercase with words separated by underscores (snake_case_function). This is also the form recommended by the PEP8 function naming recommendations (Python Software Foundation).

This PR improves consistency by converting the remaning cases of camelCaseFunction to the PEP-8 form (snake_case_function) used by convention in the repo.

@modocache - do you have time to review? That would be really appreciated :-)

@gribozavr
Copy link
Contributor

@swift-ci Please test

@modocache
Copy link
Contributor

Awesome! What's left before we can activate the .pep8 rule for method/variable names?

@@ -21,4 +21,4 @@
Bindings for the sourcekitd framework.
"""

__all__ = ['capi', 'request']
__all__ = ('capi', 'request')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these transformations to __all__ are probably incorrect, no? As far as I know, __all__ is a list, not a tuple.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did your search and replace misfire?

@modocache
Copy link
Contributor

This looks great, aside from the changes to __all__--the documentation indicates that it should be a list: https://docs.python.org/2/tutorial/modules.html#importing-from-a-package. I have a feeling the changes to __all__ will cause CI to fail here.

@practicalswift
Copy link
Contributor Author

@modocache Thanks for reviewing! :-)

The pydocstyle/pep257 tool requires __all__ to be a tuple. See discussion here: PyCQA/pydocstyle#62

When thinking of it the __all__ change has nothing to do with function naming, so I've reverted that change in 23abb10e8584e4f88d6008dd40c7aade6b8a4da0 which is now part of this PR.

Thanks for noticing!

@practicalswift
Copy link
Contributor Author

@gribozavr Merge conflicts have now been resolved :-)

@practicalswift
Copy link
Contributor Author

@gribozavr + @nadavrot Another round of newly introduced merge conflicts resolved :-)

Let me know if any changes are needed for this PR to be merged.

@practicalswift
Copy link
Contributor Author

@modocache Regarding your question about the .pep8 rule for method/variable names - do you mean the rules in pep8-naming? :-)

@gottesmm
Copy link
Contributor

@swift-ci Please test

@practicalswift
Copy link
Contributor Author

@gottesmm Both builds passed. Are there any further changes needed for this PR to be merged? :-)

@gottesmm
Copy link
Contributor

@practicalswift Out of curiosity, how did you generate the changes? Were you using something like rope?

@gottesmm
Copy link
Contributor

@practicalswift The reason why I am asking is I want to know if I should lint the code while reviewing since some of this code is not invoked by the normal build.

@practicalswift
Copy link
Contributor Author

@gottesmm All changes were made manually using query-replace in Emacs :-) However, I used flake8 to identify the issues.

I also used git grep … extensively to double-check that all references were covered by the renames.

@practicalswift
Copy link
Contributor Author

Another newly introduced merge conflict now resolved :-)

@practicalswift
Copy link
Contributor Author

@gottesmm This oneliner can be used to list the old names of the renamed functions:

$ git log -u -n 1 | egrep '^-.*def ' | cut -b2- | sed 's/^ *//g' | cut -f1 -d'(' | awk '{ print $2 }' | sort | uniq
accumulateCode
addFunction
addLine
addPass
appendText
bodyLines
codeStartsWithDedentKeyword
compareFunctionSizes
compareScores
compareSizes
compareSizesOfFile
compileOpaqueCFile
compileSource
compileSources
computeItersNumber
executeTemplate
formatChildren
get_BMP_data_offset
get_BMP_first_level_index
get_grapheme_cluster_break_tests_as_UTF8
getLineStarts
getScores
getSuccs
_int_list_to_LE_bytes
_int_to_LE_bytes
isMaxScore
listFunctionSizes
nextToken
numeric_type_names_Macintosh_only
parseArguments
parseBenchmarkOutput
parseGenericOperator
parseInt
parseProtocol
parseTemplate
posToLine
Print
printBestScores
printCommand
Process
processSource
processSources
readSizes
reportResults
runBench
runBenchmarks
runCommand
splitGybLines
splitLines
stripTrailingNL
submit_to_LNT
tokenGenerator
tokenizePythonToUnmatchedCloseCurly
tokenizeTemplate
tokenPosToIndex

@practicalswift
Copy link
Contributor Author

And this to search for occurrences of the old names of the functions to make sure there are no remaining references to them in the repo:

$ for OLD_NAME in $(git log -u -n 1 | egrep '^-.*def ' | cut -b2- | sed 's/^ *//g' | cut -f1 -d'(' | awk '{ print $2 }' | sort | uniq); do echo "[search for: '${OLD_NAME}']"; git grep -e "${OLD_NAME}[^a-zA-Z]" | egrep -v '\.(cpp|h|swift|sil|md|txt|json|mm|td|def):'; done
[search for: 'accumulateCode']
[search for: 'addFunction']
[search for: 'addLine']
[search for: 'addPass']
[search for: 'appendText']
[search for: 'bodyLines']
[search for: 'codeStartsWithDedentKeyword']
[search for: 'compareFunctionSizes']
[search for: 'compareScores']
[search for: 'compareSizes']
[search for: 'compareSizesOfFile']
[search for: 'compileOpaqueCFile']
[search for: 'compileSource']
[search for: 'compileSources']
[search for: 'computeItersNumber']
[search for: 'executeTemplate']
[search for: 'formatChildren']
[search for: 'get_BMP_data_offset']
[search for: 'get_BMP_first_level_index']
[search for: 'get_grapheme_cluster_break_tests_as_UTF8']
[search for: 'getLineStarts']
[search for: 'getScores']
[search for: 'getSuccs']
[search for: '_int_list_to_LE_bytes']
[search for: '_int_to_LE_bytes']
[search for: 'isMaxScore']
[search for: 'listFunctionSizes']
[search for: 'nextToken']
[search for: 'numeric_type_names_Macintosh_only']
[search for: 'parseArguments']
[search for: 'parseBenchmarkOutput']
[search for: 'parseGenericOperator']
[search for: 'parseInt']
[search for: 'parseProtocol']
[search for: 'parseTemplate']
[search for: 'posToLine']
[search for: 'Print']
stdlib/public/core/Arrays.swift.gyb:      debugPrint(item, terminator: "", toStream: &result)
stdlib/public/core/HashedCollections.swift.gyb:      debugPrint(member, terminator: "", toStream: &result)
stdlib/public/core/HashedCollections.swift.gyb:      debugPrint(k, terminator: "", toStream: &result)
stdlib/public/core/HashedCollections.swift.gyb:      debugPrint(v, terminator: "", toStream: &result)
utils/build-script-impl:# Print instructions for using this script to stdout
utils/error_enum_to_cases.pl:# Print properties for the ranges.
utils/find-unused-diagnostics.sh:# Print all diags that occur in the .td files but not in the source.
utils/swift-api-dump.py:    parser.add_argument('-v', '--verbose', action='store_true', help='Print extra information.')
utils/swift-api-dump.py:# Print out the command we're about to execute
utils/swift_build_support/swift_build_support/debug.py:# swift_build_support/debug.py - Print information on the build -*- python -*-
utils/swift_build_support/swift_build_support/debug.py: Print the host machine's `xcodebuild` version, as well as version
[search for: 'printBestScores']
[search for: 'printCommand']
[search for: 'Process']
benchmark/scripts/Benchmark_Driver:            print "Process output:\n", e.output
benchmark/scripts/Benchmark_RuntimeLeaksRunner.in:            print("Child Process Failed! (%s,%s)" % (data['path'], data['test_name']))
cmake/modules/AddSwift.cmake:# Process the sources within the given variable, pulling out any Swift
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:  print("$ \(Process.arguments[0]) " +
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:func _childProcess() {
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:struct _ParentProcess {
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:  internal var _runTestsInProcess: Bool
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:  init(runTestsInProcess: Bool, args: [String], filter: String?) {
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:    self._runTestsInProcess = runTestsInProcess
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:        if _runTestsInProcess {
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:  let _isChildProcess: Bool =
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:    Process.arguments.contains("--stdlib-unittest-run-child")
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:  if _isChildProcess {
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:    _childProcess()
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:    var runTestsInProcess: Bool = false
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:    while i < Process.arguments.count {
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:      let arg = Process.arguments[i]
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:        runTestsInProcess = true
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:        filter = Process.arguments[i + 1]
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:      args.append(Process.arguments[i])
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:    var parent = _ParentProcess(
stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb:      runTestsInProcess: runTestsInProcess, args: args, filter: filter)
utils/profdata_merge/process.py:class ProfdataMergerProcess(Process):
utils/profdata_merge/process.py:        super(ProfdataMergerProcess, self).__init__()
utils/profdata_merge/runner.py:    processes = [ProfdataMergerProcess(config, file_queue) for _ in range(10)]
utils/profdata_merge/runner.py:    merge_final = ProfdataMergerProcess(config, file_queue)
utils/swift-bench.py:  if Process.arguments.count > 1 {
utils/swift-bench.py:    N = Process.arguments[1].toInt()!
utils/swift-bench.py:  if Process.arguments.count <= 2 || Process.arguments[2] == name {
[search for: 'processSource']
[search for: 'processSources']
[search for: 'readSizes']
[search for: 'reportResults']
[search for: 'runBench']
[search for: 'runBenchmarks']
[search for: 'runCommand']
[search for: 'splitGybLines']
[search for: 'splitLines']
[search for: 'stripTrailingNL']
[search for: 'submit_to_LNT']
[search for: 'tokenGenerator']
[search for: 'tokenizePythonToUnmatchedCloseCurly']
[search for: 'tokenizeTemplate']
[search for: 'tokenPosToIndex']

@gottesmm
Copy link
Contributor

Ok. I am going to just run it through pylint and then I will merge assuming nothing comes up.

@practicalswift
Copy link
Contributor Author

@gottesmm Excellent! 👍 Thanks!

@gottesmm
Copy link
Contributor

pylint -E was not clean, but none of it was due to this commit. This commit LGTM.

gottesmm added a commit that referenced this pull request Feb 29, 2016
[Python] Improve Python consistency: Use function_name(…) throughout (PEP8)
@gottesmm gottesmm merged commit e7738bb into swiftlang:master Feb 29, 2016
MaxDesiatov added a commit that referenced this pull request Oct 19, 2020
Use fatal_error instead of diagnostics in build-script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants