-
Notifications
You must be signed in to change notification settings - Fork 339
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
Type hinting #258
Comments
Do you mean annotations? Something like this: def function(num: float) -> int:
pass Right? |
Yes. |
I thinks that we can add annotations. What about Python 3.4? |
Seems like annotations was added in Python 3.0. And we lose nothing. |
@sobolevn Soooo... What shall we do? Refusing to support Python 3.4 doesn't seem to be a good idea. |
It actually is in some cases. Since upgrading from |
@sobolevn Let's do this! |
Please, note that variable annotations is not supported in So, we have to annotate methods and functions only. |
@sobolevn I will add annotations for functions and methods. Can i hope for your help with situations which confuse me? |
Example: def randints(self, amount: int = None, a: int = 1, b: int = 100) -> list:
"""Generate list of random integers.
:param amount: Amount of elements.
:param a: Minimum value of range.
:param b: Maximum value of range.
:return: List of random integers.
"""
if not amount:
amount = 3
return [self.randint(a, b)
for _ in range(amount)] Is it right that |
@sobolevn How to be if the function returns multiple types using? Should we use |
In regular About function returning multiple types. That's a code smell for me. It is error prone for many reasons:
So, consider not to do it. |
@sobolevn Problem is in standard python library. |
So, seems like i have found a solution. |
With the provided solution there are a lot of uncovered cases, which are valid
|
@lk-geimfari I've already mentioned this in #267, but if one is defaulting the argument to def randints(self, amount: Optional[int] = None, a: int = 1, b: int = 100) -> list:
"""Generate list of random integers.
:param amount: Amount of elements.
:param a: Minimum value of range.
:param b: Maximum value of range.
:return: List of random integers.
"""
if amount is None:
amount = 3
return [self.randint(a, b) for _ in range(amount)] By the way, I believe I mistakenly reversed the logic of that predicate in my PR earlier :P |
@bjd2385 I'll update code using |
Sooo, it's done! |
I have started to use
mypy
. Aaaand it is not so good right now.Libraries lack typing support. And I know that
mimesis
support onlypython3
.Do you consider adding type hints?
There are some advantages:
There are some disadvantages:
python3.5
, so any version prior to that will have to use special comments or other hacksThe text was updated successfully, but these errors were encountered: