Fix: numbers in snake_case are merged with the preceding word#74
Fix: numbers in snake_case are merged with the preceding word#74hit9 merged 2 commits intohit9:masterfrom
Conversation
- E.g. MY_123_ENUM gets split into my123_enum - Refactor to make it easier to debug the intermediate steps
|
Building on top of this, I've experimented a bit with splitting numbers from words as well. I think I've found a fairly intuitive approach, but it relies on a few assumptions and there could be edge-cases I've not thought of. So I'd be interested in your opinion on it before I open a PR. @hit9 |
|
Thanks ! However, here are still some bad cases: In [4]: snake_case("HTTPServer")
Out[4]: 'httpserver' # expect: 'http_server' , works before but fails now
In [5]: snake_case("getHTTPResponseCode")
Out[5]: 'get_httpresponse_code' # expect: 'get_http_response_code', works before but fails now
In [7]: snake_case("Snake42Case")
Out[7]: 'snake42case' # expect: 'snake_42_case' , fails both before ('snake42_case') and after change
In [15]: snake_case("__init__")
Out[15]: 'init' # expect: '__init__' (without changes)
In [16]: snake_case("GPU3DModel")
Out[16]: 'gpu3dmodel' # expect: 'gpu_3_d_model' (bests to 'gpu_3d_model', but it's hard for a ‘non-human’ program.. and, rules of thumb are innumerable)Also, thanks for the proposal — I agree with the principles. One design approach that I and ChatGPT came up with is this:: Snake case — practical rules (with one example each)
And the changes based on this approach are implemented in this pr : #75 |
E.g. an enum value called
MY_123_ENUMgets split intomy123_enum, which is then uppercased toMY123_ENUM.I refactored the function to be easier to understand and debug, as each processing step can now be inspected individually.