marshmallow
marshmallow copied to clipboard
Remove unnecessary field aliases (`Str`, `Int`, `Bool`, etc.)
Marshmallow/Flask-Marshmallow provides some aliases for fields, for example, Str
and String
. To keep everything simple and consistent, I suggest removing these aliases, so that the IDE will not prompt Url
and URL
when you type "U" (in that case the users have to make the choice each time).
Proposal:
Remove the following aliases:
- Str
- Int
- Bool
- Url
- UrlFor
- AbsoluteUrlFor
Keep the following:
- String
- Integer
- Boolean
- URL
- URLFor
- AbsoluteURLFor
Originally posted in https://github.com/greyli/apiflask/issues/63
I'm unsure about this--I find the aliases to be rather convenient. Also, different projects use different conventions wrt abbreviations (e.g. URL
vs Url
), and it's kinda nice to support both.
I don't mind such a breaking change in a major release. I don't find those aliases very useful and I like to have a single way to do things. For instance, those aliases allow a team to use both namings in the same code base, making grep
more difficult.
This said, this argument and the one about code completion are kinda weak so I don't mind keeping things as they are either.
There should be one-- and preferably only one --obvious way to do it.
There's a reason Python doesn't have string
as an alias of str
in builtins
.
In my IDE the aliases lose their type and docstring. The autocomplete plugin doesn't know how to infer this information, because it doesn't try to do any runtime evaluation. We could exploit that behavior to hide the aliases from it.
# fields.py
# Aliases
globals().update({
'URL': Url,
'Str': String,
'Bool': Boolean,
'Int': Integer,
})
Purposefully evading static analysis seems unwise.