Repository navigation
Would enums/Literal be desirable for function parameters that take a limited selection of options? #423
Replies: 6 comments 1 reply
|
Great suggestion. Type hinting with StrEnum or Literal could improve the developer experience. Current State: EdgarTools already uses some enums ( StrEnum vs Literal Assessment Recommendation: StrEnum for the superior developer experience: from enum import StrEnum
class FormType(StrEnum):
ANNUAL_REPORT = "10-K"
QUARTERLY_REPORT = "10-Q"
CURRENT_REPORT = "8-K"
PROXY_STATEMENT = "DEF 14A"
FOREIGN_ANNUAL = "20-F"
# Usage
filings = company.get_filings(form=FormType.ANNUAL_REPORT)Benefits over Literal:
High-Impact Parameters Identified Based on codebase analysis, these parameters would benefit most:
What are your thoughts? |
|
@- |
StrEnum Implementation Ready for Internal Testing! 🎉Hi @EricPiazza and @dgunning! 👋 I've implemented the StrEnum approach you discussed and have a working prototype ready for community testing. This addresses the original request for type hinting with limited parameter options while maintaining perfect backwards compatibility. 🚀 Implementation CompleteNew Developer Experiencefrom edgar import Company
from edgar.formtypes import FormType
# IDE autocomplete for form types! 🚀
company = Company("AAPL")
filings = company.get_filings(form=FormType.ANNUAL_REPORT) # Auto-suggests all options
quarterly = company.get_filings(form=FormType.QUARTERLY_REPORT)
proxies = company.get_filings(form=FormType.PROXY_STATEMENT)Perfect Backwards Compatibility# All existing code continues to work unchanged
filings = company.get_filings(form="10-K") # ✅ Still works
filings = company.get_filings(form=["10-K", "10-Q"]) # ✅ Still works
# Mixed usage also supported
filings = company.get_filings(form=[FormType.ANNUAL_REPORT, "8-K"]) # ✅ Works🛠 What's IncludedFormType StrEnum with 31 common SEC forms:
✅ Testing Results✅ 31 FormType enums with correct SEC form values 🔍 Live Demo# Test it yourself!
from edgar import Company
from edgar.types import FormType
company = Company("AAPL")
# New typed usage
filings_typed = company.get_filings(form=FormType.ANNUAL_REPORT, year=2023)
print(f"Typed: {len(filings_typed)} filings")
# Original string usage
filings_string = company.get_filings(form="10-K", year=2023)
print(f"String: {len(filings_string)} filings")
# Results are identical!
assert len(filings_typed) == len(filings_string)
print("✅ Perfect compatibility confirmed")🤔 Questions for the Community
The implementation is ready on the @EricPiazza - does this address your original request for limited parameter options with type hints? |
🚀 Implementation Now Available for Testing!The FormType implementation is now pushed to GitHub and ready for community testing: Get the Code# Clone and test the implementation
git clone https://github.com/dgunning/edgartools.git
cd edgartools
git checkout feat/strenum-type-hinting
# Install in development mode
pip install -e .
# Run the demo examples
python formtype_demo_examples.pyQuick Testfrom edgar import Company
from edgar.formtypes import FormType
# Test with autocomplete
company = Company("AAPL")
filings = company.get_filings(form=FormType.ANNUAL_REPORT, year=2023)
print(f"Found {len(filings)} annual reports")
# Verify backwards compatibility
filings_old = company.get_filings(form="10-K", year=2023)
print(f"Backwards compatible: {len(filings) == len(filings_old)}")Files to Check Out
Branch Info
Please test and share your feedback! Especially interested in:
Looking forward to your thoughts! 🎯 |
|
https://github.com/dgunning/edgartools/blob/feat/strenum-type-hinting/edgar/formtypes.py |
|
That looks great! I'd definitely encourage implementing enums in other places where it makes sense, such as statement types. |
Uh oh!
There was an error while loading. Please reload this page.
There are many function parameters in the library that take a limited number of possible values, such as form types, period durations, fact summation type, etc. Currently the valid options are documented in docstrings but I think it would be helpful to limit these via parameter typing so that we get autocomplete and error detection in our IDE during development.
I ask:
StrEnumorLiteralbut there may be better methods.Thanks for reading.
All reactions