vyper icon indicating copy to clipboard operation
vyper copied to clipboard

style: snek case

Open banteg opened this issue 2 years ago • 3 comments

What I did

  • updated docs and examples with snek case
  • changed js example of event polling to ape

How I did it

wrote a script and edited by hand

import os

import inflection
from rich import print
from textblob import TextBlob
from toolz import unique

targets = [('docs', '.rst'), ('examples', '.vy')]

for dir, ext in targets:
    for root, dirs, files in os.walk(dir):
        for file in files:
            if not file.endswith(ext):
                continue
            print(f"[green]{file}")
            source = open(f"{root}/{file}").read()
            text = TextBlob(source)
            for word in unique(text.words):
                is_camel = word == inflection.camelize(word, False).replace("-", "")
                is_snek = word == inflection.underscore(word)
                if is_camel and not is_snek:
                    print(f"  {word} -> {inflection.underscore(word)}")
                    source = source.replace(word, inflection.underscore(word))

            open(f"{root}/{file}", "wt").write(source)

How to verify it

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

updated examples in documentation with snake_case

Cute Animal Picture

banteg avatar Jul 07 '22 12:07 banteg

Codecov Report

Merging #2956 (5ad8751) into master (573d77f) will decrease coverage by 29.67%. The diff coverage is n/a.

@@             Coverage Diff             @@
##           master    #2956       +/-   ##
===========================================
- Coverage   88.29%   58.62%   -29.68%     
===========================================
  Files          97       97               
  Lines       10776    10798       +22     
  Branches     2557     2498       -59     
===========================================
- Hits         9515     6330     -3185     
- Misses        804     3873     +3069     
- Partials      457      595      +138     
Impacted Files Coverage Δ
vyper/builtin_interfaces/ERC165.py 0.00% <0.00%> (-100.00%) :arrow_down:
vyper/builtin_interfaces/ERC4626.py 0.00% <0.00%> (-100.00%) :arrow_down:
vyper/builtin_interfaces/ERC20Detailed.py 0.00% <0.00%> (-100.00%) :arrow_down:
vyper/ir/s_expressions.py 5.88% <0.00%> (-88.24%) :arrow_down:
vyper/ast/natspec.py 12.34% <0.00%> (-86.42%) :arrow_down:
vyper/codegen/external_call.py 19.29% <0.00%> (-78.05%) :arrow_down:
vyper/semantics/validation/levenshtein_utils.py 16.00% <0.00%> (-76.00%) :arrow_down:
vyper/cli/utils.py 16.66% <0.00%> (-71.43%) :arrow_down:
vyper/ast/expansion.py 23.52% <0.00%> (-70.59%) :arrow_down:
vyper/compiler/utils.py 30.00% <0.00%> (-70.00%) :arrow_down:
... and 61 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 573d77f...5ad8751. Read the comment docs.

codecov-commenter avatar Jul 07 '22 14:07 codecov-commenter

another option is for interface methods to be camelCase, and local variables to be snake case

charles-cooper avatar Jul 07 '22 14:07 charles-cooper

bumping this -- @banteg looks like there are some merge conflicts now as well as some test failures

charles-cooper avatar Sep 08 '22 18:09 charles-cooper

closing since this is not passing the test suite

charles-cooper avatar Nov 07 '23 22:11 charles-cooper