Use ABCs for less-restrictive type hints.
everydaysuperpowers.dev·31w
🎯Gradual Typing
Preview
Report Post

Type hints are a great tool to communicate your intent with your code.

When starting with type hints, many people will document functions similar to how I did with this function:

def generate_reports(
reports_to_run: list[ExpiringPolicy], report_generator: FunctionType
) -> list[ReportData]:
...

If you’re not used to type hints, the code above defines a function, generate_reports , that takes two arguments:

  • reports_to_run , which is a list that contains a collection of ExpiringPolicy objects. These are objects defined in another part of the code that represents policies that will expire in a certain number of days and
  • report_generator , which is a function that creates reports for the expiring policies. The function returns a list of ReportData objects. They…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help