-
Notifications
You must be signed in to change notification settings - Fork 25
Type hints #15
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 hints #15
Conversation
…ering into development
…ering into development
Reviewer's Guide by SourceryThis pull request focuses on adding type hints to the project. It also includes extending example code to illustrate the usage of type hints and updating the project's documentation. Class diagram for the updated Person and Child classesclassDiagram
class Person {
+int id
+int age
+str name
}
class Child {
+int id
+int age [0..17]
+str name
}
Person <|-- Child
Class diagram for the new Tree implementation with type hintsclassDiagram
class Node~T~ {
-Node~T~ _left
-Node~T~ _right
-T _data
+left() Node~T~
+right() Node~T~
+data() T
+is_leaf() bool
+has_left() bool
+has_right() bool
+nr_descendants() int
+transformn(func: TransformFunc[T]) void
+visit(visit_func: VisitFunc[T], aggr_func: AggrFunc) Any
}
class Tree~T~ {
-Node~T~ _root
+root() Node~T~
+nr_of_nodes() int
+transformn(func: TransformFunc[T]) void
}
Tree *-- Node
Class diagram for the BetterPerson model with validationclassDiagram
class BetterPerson {
+int id [>=0]
+str first_name [A-Za-z- ]+
+str last_name [A-Za-z- ]+
+int age [0..120]
+validate_age(age: int) int
}
note for BetterPerson "Uses Pydantic for validation"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @gjbex - I've reviewed your changes - here's some feedback:
Overall Comments:
- There's a typo in README.md: 'introducd' should be 'introduced'
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
nr_words -= counts.pop("") | ||
for word, count in counts.items(): | ||
counts[word] /= nr_words |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Integer division could lose precision in frequency calculation
Consider converting to float before division to preserve decimal precision in the frequency calculation.
nr_words -= counts.pop("") | |
for word, count in counts.items(): | |
counts[word] /= nr_words | |
nr_words -= counts.pop("") | |
nr_words_float = float(nr_words) | |
for word, count in counts.items(): | |
counts[word] /= nr_words_float |
@@ -1,42 +1,48 @@ | |||
# Typing | |||
|
|||
Python 3.5 introducd optional type annotation for functions, and that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (typo): Typo: "introducd" should be "introduced".
Python 3.5 introducd optional type annotation for functions, and that | |
Python 3.5 introduced optional type annotation for functions, and that |
Summary by Sourcery
Add type hints to the code examples and documentation.
Enhancements:
classes.py
,classes_incorrect.py
,dict_correct.py
,dict_incorrect_01.py
,numpy_typing.py
,typed_duck_typing.py
,typed_duck_typing_wrong.py
files.dict_correct_type_statement.py
,new_types.py
, andtree.py
.Documentation: